Re: zero argument member functions versus properties

2013-11-02 Thread Steven D'Aprano
On Sat, 02 Nov 2013 23:09:09 -0700, Peter Cacioppi wrote:

> Python makes it very easy to turn a zero argument member function into a
> property (hooray!) by simply adding the @property decorator.
> 
> (Meme for well thought py feature - "Guido was here")

It is well-thought out, but it's also quite late in Python's history. 
Properties didn't get added until "new style classes" and descriptors, 
which was in version 2.2. I'm not sure if it's Guido to thank for them.


> But the ease with which you can do this makes the "zero argument member
> function or property" discussion trickier for me.
> 
> Generally my sense here is there are two extremes
> 
> 1-> the zero argument function is sort of factory-like. It potentially
> has non-trivial run time, or it substitutes calling a class constructor
> when building certain objects. 2-> it simply retrieves a stored value
> (perhaps lazily evaluating it first)


I normally go with something like this:

Something with a significant overhead (e.g. memory or running time) 
should be a method. The fact that you have to call it is a hint that it 
may require non-trivial resources/time to perform.

On the other hand, something that "feels" like it ought to be an inherent 
attribute of an object should be a property if you need it to be lazily 
calculated, or a standard attribute if you want to give direct access to 
it.

For example, imagine an object representing a printable page. The paper 
size (A4, A3, foolscap, etc.) is an inherent attribute of a page, so it 
ought to be accessed using attribute notation:

mypage.size

If this is lazily generated, or if you want to protect the attribute with 
data validation, you should use a property. Otherwise, an ordinary data 
attribute is acceptable. (This isn't Java or Ruby, where data-hiding is 
compulsory :-)

On the other hand, the Postscript image of the page is not inherent to 
the page, and it is also expensive to generate. So it ought to be 
generated lazily, only when needed, but using method notation:

mypage.postscript()


Page margins are intermediate. They feel kind of inherent to a page, but 
not exactly -- in a complex document, the margins may depend on the 
section you are in. Margins can vary depending on whether the page is at 
the left or the right. So page margins probably ought to be computed 
attributes. But they probably won't be terribly expensive to compute. So 
here I would again go with a property, assuming the page object knows 
whether it is on the left or the right, and which section it belongs to. 
But if somebody else decided that margins ought to be an explicit method, 
I wouldn't consider them wrong. It is a matter of personal taste.


[...]
> I also think that foo.size() implies that foo performs a count every
> time it's called, and foo.size implies that the run time will amortize
> to O(1) somehow (usually with lazy eval). So the implementation should
> drive the property or not decision.

I think that is reasonable. 


-- 
Steven
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Algorithm that makes maximum compression of completly diffused data.

2013-11-02 Thread Mark Janssen
>> Congratulations Jonas.  My kill file for this list used to have only one
>> name, but now has 2.
>
> You have more patience than I!  Jonas just made mine seven.  :)

Gosh, don't kill the guy.  It's not an obvious thing to hardly anyone
but computer scientists.  It's an easy mistake to make.

-- 
MarkJ
Tacoma, Washington
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Basic Python Questions - Oct. 31, 2013

2013-11-02 Thread E.D.G.
"William Ray Wing"  wrote in message 
news:mailman.1934.1383320554.18130.python-l...@python.org...



If you look here:   http://wiki.wxpython.org/MatplotlibFourierDemo


  A suggestion that I would like to add is that when people make "Demo" 
programs like that available they might want to create exe versions that 
people can download and try without installing the original programming 
language.  However, there might have been an exe version at that Web site 
and I just didn't see it.


  I myself use expendable backup computers (Windows XP) for testing new 
exe programs so that problems are not created for my primary computer.  If 
something goes wrong on one of the backup systems it is simply told to go 
back to an earlier restore point.


--
https://mail.python.org/mailman/listinfo/python-list


Re: Basic Python Questions - Oct. 31, 2013

2013-11-02 Thread E.D.G.
"Mark Lawrence"  wrote in message 
news:mailman.1873.1383227352.18130.python-l...@python.org...


https://pypi.python.org/pypi/pywinauto/0.3.9 or 
http://stackoverflow.com/questions/1823762/sendkeys-for-python-3-1-on-windows


Python "SendKey" looks like it probably works about the same as the Perl 
version. It prints or sends control information to the active window.



--
https://mail.python.org/mailman/listinfo/python-list


Re: zero argument member functions versus properties

2013-11-02 Thread Peter Cacioppi
I just said 


"1-> the zero argument function is sort of factory-like. It potentially has 
non-trivial run time, or it substitutes calling a class constructor when 
building certain objects.
2-> it simply retrieves a stored value (perhaps lazily evaluating it first)

so 1 should clearly be a zero argument member function. 2 should be a method. "

typo. Obviously, 2 should be a property.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to add a current string into an already existing list

2013-11-02 Thread Gregory Ewing

Nick the Gr33k wrote:
I just want a mysql column type that can be eligible to store an array 
of elements, a list that is, no need for having a seperate extra table 
for that if we can have a column that can store a list of values.


Relational database systems typically don't provide any
such type, because it's not the recommended way of storing
that kind of data in a relational database.

The recommended way is to use a secondary table, as has
been pointed out.

You're making things difficult for yourself by refusing
to consider that solution.

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


zero argument member functions versus properties

2013-11-02 Thread Peter Cacioppi
Python makes it very easy to turn a zero argument member function into a 
property (hooray!) by simply adding the @property decorator. 

(Meme for well thought py feature - "Guido was here")

But the ease with which you can do this makes the "zero argument member 
function or property" discussion trickier for me. 

Generally my sense here is there are two extremes

1-> the zero argument function is sort of factory-like. It potentially has 
non-trivial run time, or it substitutes calling a class constructor when 
building certain objects. 
2-> it simply retrieves a stored value (perhaps lazily evaluating it first)

so 1 should clearly be a zero argument member function. 2 should be a method.

Other than that, I say "when in doubt, go with zero argument method". In 
particular something in my gut says that if the thing I'm returning is itself a 
function, than don't go with property. In other words

foo.bar()(x) 

self documents that bar returns a function whereas 

foo.bar(x)

looks like bar is a one argument member function of foo, as opposed to a 
property that returns a 1 argument  function

I also think that foo.size() implies that foo performs a count every time it's 
called, and foo.size implies that the run time will amortize to O(1) somehow 
(usually with lazy eval). So the implementation should drive the property or 
not decision.

Sound a bit right?

Seems like some of the energetic posters will have fun with this one, re:less.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Basic Python Questions - Oct. 31, 2013

2013-11-02 Thread E.D.G.
"E.D.G."  wrote in message 
news:udgdnadga6n9vu_pnz2dnuvz_umdn...@earthlink.com...


  Thanks for all of the comments. I have been away from my Internet 
connection for several days and could not respond to them when they were 
first posted here.


  The comments have all been considered. And I am discussing them with 
other researchers that I work with. Since Perl has a calculation speed limit 
that is probably not easy to get around, before too long another language 
will be selected for initially doing certain things such as performing 
calculations and plotting charts. And the existing Perl code might then be 
gradually translated into that new language.


  Gnuplot is presently being used to draw charts. And it works. But it 
has its own limitations such as with its interaction speed when it is used 
for working with Perl program generated data files.


  My main, complex programs won't be run at Web sites. They will 
instead continue to be available as downloadable exe programs.  The CGI (or 
whatever) programming work would involve relatively simple programs. But 
they would need to be able to generate charts that would be displayed on Web 
pages. That sounds like it is probably fairly easy to do using Python. A 
Perl - Gnuplot combination is also supposed to be able to do that. But so 
far I have not seen any good explanations for how to actually get Gnuplot to 
run as a callable CGI program. So other programs such as Python are being 
considered.


--
https://mail.python.org/mailman/listinfo/python-list


Re: How to use variables across modules

2013-11-02 Thread Steven D'Aprano
On Sat, 02 Nov 2013 14:33:54 -0700, juel4700 wrote:

> Im a newbee at python, and im trying to figure out how to use variables
> and setups across modules.
[...]
> What is best practice for working across modules.

Depends on whether you are working on a framework, a library or an 
application.

Frameworks are monstrously large and complex beasts, not for beginners, 
so I won't discuss them.

Libraries are collections of re-usable code. In general, a library will 
often be in a single module. For example, the math library, which 
contains a collection of re-usable, related functions like sin, cos, tan, 
sqrt, etc.

Some code in an application is re-usable. For instance, if your 
application needs to download data from the Internet, well, lots of apps 
need to download data from the Internet, so it makes sense to pull out 
the download-data-from-the-Internet parts of your application and put 
them into a library module. But the rest of the app is likely to be too 
specific to bother. In that case, it can stay within a single file, at 
least until such point that it grows too large and unwieldy, in which 
case you can start pulling bits out into separate files.

How large is "too large" is a matter of taste, but personally I consider 
the decimal module to be about as large as a single file should get: 
about 6000-7000 lines, including comments and blank lines:

http://hg.python.org/cpython/file/3.3/Lib/decimal.py


Regardless of what you are doing, best practice is that closely related 
code should go together (in the same function, the same class, or the 
same module) and unrelated code should be separate (in a separate 
function, class or module).

Another thing to consider: best practice is to avoid using global 
variables. If you must use them -- and you almost never *need* them -- 
they should be specific to a single module. But better is to not use 
global variables at all. For example, code like this:


value = "something"  # set the global
function()  # call a function
print(result)  # which reads the global "value", and sets global "result"


should be avoided like the plague. Better is to write your functions to 
take input arguments, and return results:

result = function("something")
print(result)


One advantage -- one out of many -- is that if you write your functions 
like this, the question of how to use variables across modules is 
irrelevant. The right answer to the question "What's the best way to 
manage global variables across modules?" is "Don't".



-- 
Steven
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Basic Python Questions - Oct. 31, 2013

2013-11-02 Thread E.D.G.
"rusi"  wrote in message 
news:1e63687b-4269-42d9-8700-e3a8dcc57...@googlegroups.com...



Not sure what will… you may look at Julia: http://julialang.org/


  That program language speed comparison table looks quite interesting. 
And I asked some of the other people that I work with to take a look at the 
Web page. One or two of them might want to consider using it instead of 
XBasic assuming the calculation speeds and chart generation capabilities are 
at least roughly equal. If either of them decides to move in that direction 
I will probably try using it myself.


--
https://mail.python.org/mailman/listinfo/python-list


Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea.

2013-11-02 Thread Steven D'Aprano
On Sat, 02 Nov 2013 18:22:38 +, Joshua Landau wrote:
[...]
> Sure, you in all probability didn't mean it like that but rurpy isn't
> uncalled for in raising the concern. Really I just want to remind you
> that you're both on the same side here.

Thanks for the comments Joshua, but I'm afraid I cannot agree. I gave it 
a lot of thought and I cannot continue to give Rurpy the presumption of 
good faith any longer. This saddens me, but that's the way it is.

I'm trying hard to give up threads like this, where people debate the 
subjective tone of an email and ever more pedantic arguments about the 
precise wording. Even when all participants are arguing in good faith, 
they risk becoming quagmires which go nowhere in dozens of posts.


-- 
Steven
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Algorithm that makes maximum compression of completly diffused data.

2013-11-02 Thread Ethan Furman

On 10/30/2013 12:23 PM, jonas.thornv...@gmail.com wrote:


What i actually saying is that you are indeed... [insult snipped]


*plonk*
--
https://mail.python.org/mailman/listinfo/python-list


Re: Algorithm that makes maximum compression of completly diffused data.

2013-11-02 Thread Ethan Furman

On 10/30/2013 01:32 PM, Gene Heskett wrote:


Congratulations Jonas.  My kill file for this list used to have only one
name, but now has 2.


You have more patience than I!  Jonas just made mine seven.  :)

--
~Ethan~
--
https://mail.python.org/mailman/listinfo/python-list


Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea.

2013-11-02 Thread Chris Angelico
On Sun, Nov 3, 2013 at 6:49 AM, Skybuck Flying
 wrote:
> For those programmers that want to write clear/understandable/less buggy
> code instead of the fastest it could be interesting.

"it", without context? What could be interesting? You're not quoting
any text, so I have no idea what you're referring to. Correspondingly
in your other paragraphs.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea.

2013-11-02 Thread Skybuck Flying
For those programmers that want to write clear/understandable/less buggy 
code instead of the fastest it could be interesting.


Also ultimately compilers are free to implement it they way they want it ;) 
Thus freeing the programmer from strange assembler instruction orders as 
usual ;)


If you ever would like to write your own compiler you are free to implement 
it the way you want it and thus hopefully your assembler analysis makes 
sense ;)


Bye,
 Skybuck.


--
https://mail.python.org/mailman/listinfo/python-list


Re: Algorithm that makes maximum compression of completly diffused data.

2013-11-02 Thread Chris Angelico
On Sun, Nov 3, 2013 at 2:17 PM, Steven D'Aprano
 wrote:
> There is a way to apparently get around these limits: store data
> externally, perhaps inside the compression application itself. Then, if
> you just look at the compressed file (the "data.zip" equivalent, although
> I stress that zip compression is *not* like this), you might think it has
> shrunk quite a lot. But when you include the hidden data, the compression
> is not quite so impressive...

Storing externally is, of course, a very useful thing - it's just not
compression. For instance, a git repository (and quite likely a
Mercurial one too) keeps track of files as blobs of data referenced by
their cryptographic hashes. The current state of a directory can be
described by listing file names with their object hashes, which is a
very compact notation; but it doesn't have _all_ the information, and
the "decompression" process involves fetching file contents from the
library. It's a tool in the arsenal, but it's not compression in the
same way that PK-ZIP is.

With real compression algorithms, there's usually an "out" clause that
detects that the algorithm's doing a bad job. The file format for
PK-ZIP and, I expect, every other archiving+compression file format,
has allowances for some of the files to be stored uncompressed. That
way, there's no need for any file to be enlarged by more than some
signature - say, a one-byte "compression type" marker, or even a
one-bit mark somewhere. But enlarged they must be, for the reasons
Steven explained.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: getpeername() on stdin?

2013-11-02 Thread Nobody
On Fri, 01 Nov 2013 14:55:38 -0400, random832 wrote:

> If it's possible to get this information with only the fd, then why does
> socket.fromfd require them?

The only person who can answer that is whoever came up with
socket.fromfd() in the first place.

I initially suspected that it might have been a Windows limitation, but
socket.fromfd() is only available on Unix.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Algorithm that makes maximum compression of completly diffused data.

2013-11-02 Thread Steven D'Aprano
On Sat, 02 Nov 2013 14:31:09 -0700, Tim Roberts wrote:

> jonas.thornv...@gmail.com wrote:
>>
>>Well then i have news for you.
> 
> Well, then, why don't you share it?
> 
> Let me try to get you to understand WHY what you say is impossible.
[snip reasons]

Expanding on Tim's post... the first scenario Tim gives, applying the 
compression repeatedly to its own output until you eventually get a 
single byte, can be overcome if there are data sets that are unchanged by 
compression. That is, if f() is the compression function:

f(f(f(data))) = f(f(data)) == f(data) == data

for some values of data. So if you start with some other data, and 
compress it, then compress it again, and again, eventually you end up 
with one of these attractors, after which repeated compression doesn't 
give you any more benefit.

[Aside: the attractors aren't necessarily a single point. The attractor 
could be a cycle of two or more points, f(x) == y and f(y) == x. Or you 
could even have a "strange attractor", which brings us to chaos theory.] 

But your second reason, better known as the pigeonhole principle, 
demonstrates that for any lossless compression method, there must be data 
sets that actually expand the data. It doesn't matter how cleverly you 
compress the data, you can't fit 20kg of potatoes in a 10kg bag, so to 
speak. Suppose your compression algorithm compresses a single byte into a 
nybble (four bits). There are 256 different input data sets (0x00, 
0x01, ... 0xFF) and only 16 different outputs (0x0, 0x1, ... 0xF). There 
is no way for 256 pigeons to fit in 16 pigeon holes unless you put two or 
more pigeons in at least one hole. Ergo, if the compression algorithm is 
lossless, *some* data must be expanded rather than compressed.

Alternatively, the compression may be lossy. Or both!

Obviously data isn't compressed a byte at a time, that would be silly. 
But the principle still applies.

There is a way to apparently get around these limits: store data 
externally, perhaps inside the compression application itself. Then, if 
you just look at the compressed file (the "data.zip" equivalent, although 
I stress that zip compression is *not* like this), you might think it has 
shrunk quite a lot. But when you include the hidden data, the compression 
is not quite so impressive...


-- 
Steven
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: multiprocessing: child process race to answer (forgot to Cc: the list)

2013-11-02 Thread William Ray Wing
On Nov 2, 2013, at 11:44 AM, Sherard Hall  wrote:

> Thank you for the response. Processing time is very important so I suspect 
> having to write to disk will take more time than letting the other processes 
> complete without finding the answer. So I did some profiling one process 
> finds the answer in about 250ms, but since I can't stop the other processes, 
> it takes about 800ms before I can use the answer.  Do you recommend a global 
> variable flag? Any other suggestions?
> 
> On Nov 2, 2013 8:17 AM, "William Ray Wing"  wrote:
> On Nov 2, 2013, at 1:03 AM, smhall05  wrote:
> 
> > On Friday, November 1, 2013 10:52:40 PM UTC-4, MRAB wrote:
> >> On 02/11/2013 02:35, smhall05 wrote:
> >>
> >>> I am using a basic multiprocessing snippet I found:
> >>>
> >>> #-
> >>> from multiprocessing import Pool
> >>>
> >>> def  f(x):
> >>> return x*x
> >>>
> >>> if __name__ == '__main__':
> >>> pool = Pool(processes=4)  # start 4 worker processes
> >>> result = pool.apply_async(f, [10])# evaluate "f(10)" 
> >>> asynchronously
> >>> print result.get(timeout=1)
> >>> print pool.map(f, range(10))  # prints "[0, 1, 4,..., 81]"
> >>> #-
> >>>
> >>> I am using this code to have each process go off and solve the same 
> >>> problem, just with different inputs to the problem. I need to be able to 
> >>> kill all processes once 1 of n processes has come up with the solution. 
> >>> There will only be one answer.
> >>>
> >>> I have tried:
> >>>
> >>> sys.exit(0) #this causes the program to hang
> >>> pool.close()
> >>> pool.terminate
> >>>
> >>
> >> Did you actually mean "pool.terminate", or is that a typo for
> >>
> >> "pool.terminate()"?
> >>
> >>> These still allow further processing before the program terminates. What 
> >>> else can I try? I am not able to share the exact code at this time. I can 
> >>> provide more detail if I am unclear. Thank you
> >>>
> >
> > I am not sure to be honest, however it turns out that I can't use 
> > pool.terminate() because pool is defined in main and not accessible under 
> > my def in which I check for the correct answer.
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> 
> So, the simplest solution to that situation is to have whichever subprocess 
> that finds the correct answer set a flag which the calling process can check. 
>  Depending on your OS, that flag can be anything from setting a lock to 
> something as simple as creating a file which the calling process periodically 
> wakes up and looks for, maybe just a file in which the subprocess has written 
> the answer.
> 
> Bill
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list

Well, the multiprocessing library provides listeners and clients that wrap BSD 
style sockets and allow you to send (push) arbitrary python objects to a 
listener, i.e., the master.  There might be something better that was OS 
specific, but this will keep it pure python.  I've not tested it, but there is 
a simple example here on Stackoverflow: 

http://stackoverflow.com/questions/6920858/interprocess-communication-in-python

-Bill-- 
https://mail.python.org/mailman/listinfo/python-list


Re: New to using re. Search for a number before a string.

2013-11-02 Thread Mark Lawrence

On 03/11/2013 00:19, Captain Dunsel wrote:

On Friday, November 1, 2013 5:33:43 PM UTC-4, Captain Dunsel wrote:

I have a text file that has lines with numbers occasionally appearing right 
before a person's name.  For example:



COLLEGE:ENROLLMENT:COMPLETED EVALUATIONS:624309FUDD, ELMER



where I want to search for the name "ELMER FUDD" and extract the number right in front of it 
"608309" when such a number appears but the length of the number is variable and using 
?<= in a regular expression will only search for a fixed length.



Any ideas appreciated!


Thanks for your help, everyone!



My invoice, like the proverbial cheque, is in the post :)

Slight aside, in order to avoid the unwanted newlines above could you 
please read and action this, thanks 
https://wiki.python.org/moin/GoogleGroupsPython


--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


Re: New to using re. Search for a number before a string.

2013-11-02 Thread Captain Dunsel
On Friday, November 1, 2013 5:33:43 PM UTC-4, Captain Dunsel wrote:
> I have a text file that has lines with numbers occasionally appearing right 
> before a person's name.  For example:
> 
> 
> 
> COLLEGE:ENROLLMENT:COMPLETED EVALUATIONS:624309FUDD, ELMER
> 
> 
> 
> where I want to search for the name "ELMER FUDD" and extract the number right 
> in front of it "608309" when such a number appears but the length of the 
> number is variable and using ?<= in a regular expression will only search for 
> a fixed length.
> 
> 
> 
> Any ideas appreciated!

Thanks for your help, everyone!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to use variables across modules

2013-11-02 Thread Mark Lawrence

On 02/11/2013 21:33, juel4...@gmail.com wrote:

Im a newbee at python, and im trying to figure out how to use variables and 
setups across modules.

Am I right when i think its smart to keep seperate functions of a program in 
seperate modules?


If your code base gets too large to handle in one module sure.  If it's 
only a few hundred lines of code why bother?




I have a main program module called main.py and in that main.py i have this:

 # Sets GPIO's to HIGH = Relays OFF
 try:
 import RPi.GPIO as GPIO
 except RuntimeError:
 Print("Error importing RPi.GPIO!!")


You catch the wrong error, it should be ImportError.  Correct this and 
you print a pretty message and continue so...




 GPIO.setmode(GPIO.BOARD)


...you'll get a traceback here as your code knows nothing about GPIO 
because of the ImportError that you've so carefully mishandled.  Don't 
worry about it, we've all done it at one time or another :)



 GPIO.setwarnings(False)
 # GPIO16 is relay1
 GPIO.setup(16, GPIO.OUT, initial=GPIO.HIGH)
 # GPIO11 is relay2
 GPIO.setup(11, GPIO.OUT, initial=GPIO.HIGH)

I then import a module (in that module1 i have a function called Relay) and try 
to use the function with module1.Relay(1,1)

But the function in module1 needs the GPIO from the main.py to Work. How do I 
go about with this? I really dont want the GPIO setting part in the module1, I 
dont want it to be run everytime I run the module1.Relay(1,1) call..



Keeping everything in one module is actually the simplest approach.  If 
you want to keep separate modules repeat the GPIO import as needed.  The 
thing to beware of is circular imports if you have many modules.



What is best practice for working across modules. (im making a controller for 
my house' heat system, so it would be nice, if I can do this the right way, the 
first time.)

Im and experienced vbs and php coder, but a real newbe when it comes to python 
;)

I Really hope you Guys will lead me in the right direction..

Kind regards Juel



Finally if you're using google groups would you be kind enough to read, 
digest and action this https://wiki.python.org/moin/GoogleGroupsPython


--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


Re: How to add a current string into an already existing list

2013-11-02 Thread Chris Angelico
On Sun, Nov 3, 2013 at 9:00 AM, Roy Smith  wrote:
> In article ,
>  Chris Angelico  wrote:
>
>> On Sun, Nov 3, 2013 at 5:30 AM, Jussi Piitulainen
>>  wrote:
>> > Suppose a database allowed structured values like lists of strings,
>> > lists of numbers, or even lists of such lists and more. Then it would
>> > actually be a Python issue how best to support that database.
>>
>> PostgreSQL supports some higher-level structures like arrays.
>> Personally, though, I think the most general representation of a
>> Python list in a database is either a varchar field with some form of
>> structure (eg the repr of a list), or a separate table with a foreign
>> key back to this one.
>
> When you say "database" here, you're really talking about relational
> databases.  There are other kinds.

Quite right, my apologies. I'm talking about the classic relational
database accessed by SQL, which is what the OP's currently working
with (MySQL). I've worked with other types of database, but was trying
to stick as closely as possible to the question. But yes, the
clarification is important here.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to use variables across modules

2013-11-02 Thread Chris Angelico
On Sun, Nov 3, 2013 at 8:33 AM,   wrote:
> I have a main program module called main.py and in that main.py i have this:
>
> # Sets GPIO's to HIGH = Relays OFF
> try:
> import RPi.GPIO as GPIO
> except RuntimeError:
> Print("Error importing RPi.GPIO!!")
>
> GPIO.setmode(GPIO.BOARD)
> GPIO.setwarnings(False)
> # GPIO16 is relay1
> GPIO.setup(16, GPIO.OUT, initial=GPIO.HIGH)
> # GPIO11 is relay2
> GPIO.setup(11, GPIO.OUT, initial=GPIO.HIGH)
>
>
> But the function in module1 needs the GPIO from the main.py to Work. How do I 
> go about with this? I really dont want the GPIO setting part in the module1, 
> I dont want it to be run everytime I run the module1.Relay(1,1) call..

I don't know what GPIO is, but I suspect that you'll do best to simply
import it in module1 same as you do in main. You'll get the same
module (Python caches imported modules), so any configuration done
will apply to both.

But you might not need to separate out your modules. It's quite
alright to have a fairly large main module in Python, with lots of
functions. You'd have to figure that out separately, as a design
question.

A few other points about your code, if I may!

1) Is Print a custom function of yours? If not, please be more careful
with copying and pasting code - it makes a lot of difference.

2) If RPi.GPIO can't be imported, you emit a message and (presumably)
keep going. That's pretty useless - your script will bomb with a
NameError as soon as it tries to use GPIO. Better to simply not catch
anything around that import, and if there's a problem, the exception
will be displayed (usefully!) and the script terminated. "Have you not
heard the expression 'Never test for an error condition you don't know
how to handle'?" [1]

3) You're using Google Groups, which means your post is misformatted -
and which means that replies will be, unless you specifically work to
prevent it, very much misformatted and ugly. Please don't do that. If
you must use Google Groups, please read
https://wiki.python.org/moin/GoogleGroupsPython and follow it; but due
to the many problems with GG, there are a number of people who simply
killfile every post from there, so they won't even see it. Switching,
either to a better newsreader or to email, will solve all those
problems at once.

[1] http://www.theregister.co.uk/2008/10/24/bofh_2008_episode_34/

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to add a current string into an already existing list

2013-11-02 Thread Roy Smith
In article ,
 Chris Angelico  wrote:

> On Sun, Nov 3, 2013 at 5:30 AM, Jussi Piitulainen
>  wrote:
> > Suppose a database allowed structured values like lists of strings,
> > lists of numbers, or even lists of such lists and more. Then it would
> > actually be a Python issue how best to support that database.
> 
> PostgreSQL supports some higher-level structures like arrays.
> Personally, though, I think the most general representation of a
> Python list in a database is either a varchar field with some form of
> structure (eg the repr of a list), or a separate table with a foreign
> key back to this one.

When you say "database" here, you're really talking about relational 
databases.  There are other kinds.

In MongoDB, for example, storing a list of lists of strings is a 
perfectly reasonable and straight-forward thing to do.  Anything which 
can be represented by bson (which is more or less the same as anything 
which can be represented by json) can be inserted directly.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to add a current string into an already existing list

2013-11-02 Thread Chris Angelico
On Sun, Nov 3, 2013 at 5:30 AM, Jussi Piitulainen
 wrote:
> Suppose a database allowed structured values like lists of strings,
> lists of numbers, or even lists of such lists and more. Then it would
> actually be a Python issue how best to support that database.

PostgreSQL supports some higher-level structures like arrays.
Personally, though, I think the most general representation of a
Python list in a database is either a varchar field with some form of
structure (eg the repr of a list), or a separate table with a foreign
key back to this one.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Algorithm that makes maximum compression of completly diffused data.

2013-11-02 Thread Mark Janssen
> Let me try to get you to understand WHY what you say is impossible.  Let's
> say you do have a function f(x) that can produce a compressed output y for
> any given x, such that y is always smaller than x.  If that were true, then
> I could call f() recursively:
> f(f(...f(f(f(f(f(x)...))
> and eventually the result get down to a single bit.  I hope it is clear
> that there's no way to restore a single bit back into different source
> texts.

Hey, that's a nice proof!

Cheers,

Mark Janssen
-- 
https://mail.python.org/mailman/listinfo/python-list


How to use variables across modules

2013-11-02 Thread juel4700
Im a newbee at python, and im trying to figure out how to use variables and 
setups across modules.

Am I right when i think its smart to keep seperate functions of a program in 
seperate modules?

I have a main program module called main.py and in that main.py i have this:

# Sets GPIO's to HIGH = Relays OFF
try:
import RPi.GPIO as GPIO
except RuntimeError:
Print("Error importing RPi.GPIO!!")

GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
# GPIO16 is relay1
GPIO.setup(16, GPIO.OUT, initial=GPIO.HIGH)
# GPIO11 is relay2
GPIO.setup(11, GPIO.OUT, initial=GPIO.HIGH)

I then import a module (in that module1 i have a function called Relay) and try 
to use the function with module1.Relay(1,1)

But the function in module1 needs the GPIO from the main.py to Work. How do I 
go about with this? I really dont want the GPIO setting part in the module1, I 
dont want it to be run everytime I run the module1.Relay(1,1) call..

What is best practice for working across modules. (im making a controller for 
my house' heat system, so it would be nice, if I can do this the right way, the 
first time.)

Im and experienced vbs and php coder, but a real newbe when it comes to python 
;)

I Really hope you Guys will lead me in the right direction..

Kind regards Juel
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Algorithm that makes maximum compression of completly diffused data.

2013-11-02 Thread Tim Roberts
jonas.thornv...@gmail.com wrote:
>
>Well then i have news for you.

Well, then, why don't you share it?

Let me try to get you to understand WHY what you say is impossible.  Let's
say you do have a function f(x) that can produce a compressed output y for
any given x, such that y is always smaller than x.  If that were true, then
I could call f() recursively:
f(f(...f(f(f(f(f(x)...))
and eventually the result get down to a single bit.  I hope it is clear
that there's no way to restore a single bit back into different source
texts.

Here's another way to look at it.  If f(x) is smaller than x for every x,
that means there MUST me multiple values of x that produce the same f(x).
Do you see?  If x is three bits and f(x) is two bits, that means there are
8 possible values for x but only 4 values for f(x).  So, given an f(x), you
cannot tell which value of x it came from.  You have lost information.
-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to add a current string into an already existing list

2013-11-02 Thread Walter Hurry
On Sat, 02 Nov 2013 10:40:58 -0700, rusi wrote:

> That Codd...
> Should have studied some computer science
> 
> [Ive a vague feeling I am repeating myself...]

ROFL. Get thee into FNF!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: First day beginner to python, add to counter after nested loop

2013-11-02 Thread Tim Roberts
jonas.thornv...@gmail.com wrote:
>
>I certainly do not like the old bracket style it was a catastrophe, but 
>in honesty the gui editor of python should have what i propose, a parser
>that indent automaticly at loops, functions and end.

Many editors do that.  Vim, which is what I use, certainly does.

>I promise you it will save millions of hours of bug searching all over 
>world in a month.

I suspect you meant "dozens" rather than "millions"...

Look, both schemes have their pitfalls.  With an "end" requirement, it's
easy to have code where the indenting doesn't match the actual nesting, and
that causes human confusion.  Without the "end" requirement, it's not hard
to type code where you forget to dedent.  Those are just two manifestations
of the exact same problem.  Neither scheme is provably superior to the
other.  It's just a choice that a language designer has to make.

I happen to like Python's choice.  You'll get used to it.
-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea.

2013-11-02 Thread Peter Cacioppi
Mark said :

"The White Flag before this also escalates out of control. "

This word "before" ... I don't think it means what you think it means. 

This thread has been off the rails for days.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Printing appropriately based on values retrieved

2013-11-02 Thread Nick the Gr33k

Στις 2/11/2013 8:25 μμ, ο/η Nick the Gr33k έγραψε:

for row in newdata:
(host, refs, city, useros, browser, visits, hits, downloads) = row

 if downloads != 'Δεν έχει κατεβάσει ταινία':
 print( '' )
 for n, download in enumerate( downloads ):
 if n == 0:
 op_selected = 'selected'
 else:
 op_selected = ''
 print( ' %s ' % (op_selected, download) )
 print( '' )
 else:
 print( ' 'No downloads yet'
' )


The above code is supposed to print a select menu in case it has found
tha user has downloaded files from my website and if he didn't to just
print a string 'No downloads yet'.

Unfortunately as i have it, it prints 'No downloads yet' inside a select
menu giving the impression that the 'No downloads yet' was actually a file.

how should i write it to have the result i want it to be?



--
if downloads != 'Δεν έχει κατεβάσει ακόμη ταινία!':
print( '' )
for n, download in enumerate( downloads ):
if n == 0:
op_selected = 'selected'
else:
op_selected = ''
print( ' %s ' % (op_selected, download) )
print( '' )
times = times + 1

if times == 0:
	print( ' Δεν έχει κατεβάσει ακόμη 
ταινία! ' )


I just tried this this didn't work either :(
Please someone t
--
https://mail.python.org/mailman/listinfo/python-list


Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea.

2013-11-02 Thread Mark Lawrence

On 02/11/2013 18:22, Joshua Landau wrote:

On 1 November 2013 05:41, Steven D'Aprano
 wrote:

On Thu, 31 Oct 2013 21:41:32 -0700, rurpy wrote:


On 10/31/2013 02:41 AM, Steven D'Aprano wrote:

On Wed, 30 Oct 2013 19:48:55 -0700, rurpy wrote:

On 10/30/2013 04:22 AM, Steven D'Aprano wrote:

Skybuck's experience at programming *is relevant* to the question of
whether or not he understands what he is talking about.

No.  You claimed his proposition "made no sense" based on your
analysis of it.


I said absolutely nothing of the sort. You're making that quote up --
not just misinterpreting what I said, or taking my words in the worst
possible way, but completely inventing things I never said.


Yes, on rereading you are correct, you did not say his proposition made
no sense, you disagreed with him that "putting this exit condition on
the top makes no sense" and claimed he had no business making such a
statement


I said nothing of the sort.


Personally, rurpy's reading seems like a reasonable one to me. Maybe
not correct in a technical sense, but at least reasonable.

Particularly, the phrase

"Wait until you actually start programming before deciding what makes
sense or doesn't."

seems especially harsh, and would be furthermore so should Skybuck be
a professional programmer. That's a phrase easy to take badly,
especially over this medium.

Sure, you in all probability didn't mean it like that but rurpy isn't
uncalled for in raising the concern. Really I just want to remind you
that you're both on the same side here.



Coming from me this is probably a classic case of pot calling the kettle 
black, but how about reading the Spike Milligan story The White Flag 
before this also escalates out of control.


--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


Re: How to add a current string into an already existing list

2013-11-02 Thread Jussi Piitulainen
rusi writes:

> On Saturday, November 2, 2013 10:13:06 PM UTC+5:30, Denis McMahon wrote:
> > On Sat, 02 Nov 2013 18:25:31 +0200, Nick the Gr33k wrote:
> 
> > > I just want a mysql column type that can be eligible to store an
> > > array of elements, a list that is, no need for having a seperate
> > > extra table for that if we can have a column that can store a
> > > list of values.
> 
> > You'd better take that up with the mysql designers.
> 
> That Codd... 
> Should have studied some computer science
> 
> [Ive a vague feeling I am repeating myself...]

Date and Darwen think that SQL designers should have studied and
implemented relational theory (Codd's database theory). This doesn't
contradict you, of course - possibly Codd should have studied CS.

Date and Darwen think also that structured values like sets and
relations should be allowed in a database and supported by the query
language. Maybe their work should be taken as what Codd might think
today, while the implementors of SQL products go their own merry ways.

I grepped through one SQL standard on the web once to see how it
refers to relational theory. Every single occurrence of "relation" was
a substring of "correlational value" or something like that. My take
from that is that SQL doesn't even pretend to be an implementation of
Codd's theory.

Suppose a database allowed structured values like lists of strings,
lists of numbers, or even lists of such lists and more. Then it would
actually be a Python issue how best to support that database.
-- 
https://mail.python.org/mailman/listinfo/python-list


Printing appropriately based on values retrieved

2013-11-02 Thread Nick the Gr33k

for row in newdata:
(host, refs, city, useros, browser, visits, hits, downloads) = row

if downloads != 'Δεν έχει κατεβάσει ταινία':
print( '' )
for n, download in enumerate( downloads ):
if n == 0:
op_selected = 'selected'
else:
op_selected = ''
print( ' %s ' % (op_selected, 
download) )
print( '' )
else:
print( ' 'No downloads yet' 
' )


The above code is supposed to print a select menu in case it has found 
tha user has downloaded files from my website and if he didn't to just 
print a string 'No downloads yet'.


Unfortunately as i have it, it prints 'No downloads yet' inside a select 
menu giving the impression that the 'No downloads yet' was actually a file.


how should i write it to have the result i want it to be?
--
https://mail.python.org/mailman/listinfo/python-list


Re: How to add a current string into an already existing list

2013-11-02 Thread Mark Lawrence

On 02/11/2013 17:40, rusi wrote:

On Saturday, November 2, 2013 10:13:06 PM UTC+5:30, Denis McMahon wrote:

On Sat, 02 Nov 2013 18:25:31 +0200, Nick the Gr33k wrote:



I just want a mysql column type that can be eligible to store an array
of elements, a list that is, no need for having a seperate extra table
for that if we can have a column that can store a list of values.



You'd better take that up with the mysql designers.


That Codd...
Should have studied some computer science

[Ive a vague feeling I am repeating myself...]



A local lad as well, he's brought nothing but disgrace on the area. 
Apart from the fact that the vast majority of locals have never ever 
heard of him.


--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea.

2013-11-02 Thread Joshua Landau
On 1 November 2013 05:41, Steven D'Aprano
 wrote:
> On Thu, 31 Oct 2013 21:41:32 -0700, rurpy wrote:
>
>> On 10/31/2013 02:41 AM, Steven D'Aprano wrote:
>>> On Wed, 30 Oct 2013 19:48:55 -0700, rurpy wrote:
 On 10/30/2013 04:22 AM, Steven D'Aprano wrote:
> Skybuck's experience at programming *is relevant* to the question of
> whether or not he understands what he is talking about.
 No.  You claimed his proposition "made no sense" based on your
 analysis of it.
>>>
>>> I said absolutely nothing of the sort. You're making that quote up --
>>> not just misinterpreting what I said, or taking my words in the worst
>>> possible way, but completely inventing things I never said.
>>
>> Yes, on rereading you are correct, you did not say his proposition made
>> no sense, you disagreed with him that "putting this exit condition on
>> the top makes no sense" and claimed he had no business making such a
>> statement
>
> I said nothing of the sort.

Personally, rurpy's reading seems like a reasonable one to me. Maybe
not correct in a technical sense, but at least reasonable.

Particularly, the phrase

"Wait until you actually start programming before deciding what makes
sense or doesn't."

seems especially harsh, and would be furthermore so should Skybuck be
a professional programmer. That's a phrase easy to take badly,
especially over this medium.

Sure, you in all probability didn't mean it like that but rurpy isn't
uncalled for in raising the concern. Really I just want to remind you
that you're both on the same side here.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to add a current string into an already existing list

2013-11-02 Thread rusi
On Saturday, November 2, 2013 10:13:06 PM UTC+5:30, Denis McMahon wrote:
> On Sat, 02 Nov 2013 18:25:31 +0200, Nick the Gr33k wrote:

> > I just want a mysql column type that can be eligible to store an array
> > of elements, a list that is, no need for having a seperate extra table
> > for that if we can have a column that can store a list of values.

> You'd better take that up with the mysql designers.

That Codd... 
Should have studied some computer science

[Ive a vague feeling I am repeating myself...]
-- 
https://mail.python.org/mailman/listinfo/python-list


Acquiring Python Consulting Clients

2013-11-02 Thread Mark Richman
If you're an independent Python developer/consultant, would you share some tips 
on acquiring clients? 

--
Mark Richman
markrichman.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python on a MacBook Pro (not my machine)

2013-11-02 Thread rusi
On Saturday, November 2, 2013 10:26:01 PM UTC+5:30, paul@rudin.co.uk wrote:
> "nf7" writes:

> > MacVim is the best text editor...

> fighting talk!

> :)

No I am not muscular enough to return the fighting talk...
Except to say that nf7 is top-posting
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python on a MacBook Pro (not my machine)

2013-11-02 Thread paul . nospam
"nf7"  writes:

> MacVim is the best text editor...

fighting talk!

:)

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python on a MacBook Pro (not my machine)

2013-11-02 Thread nf7
MacVim is the best text editor, but the key bindings might get in the way at 
first. I'd still suggest it though. Also, installing a version of Python 
from the website is a good idea since Apple has a custom (and usually older) 
version of Python pre-installed that functions a little differently.



"rusi"  wrote in message 
news:14f678dc-a69c-489d-a120-ea5e0a1b2...@googlegroups.com...


On Sunday, October 27, 2013 12:37:40 AM UTC+5:30, John Ladasky wrote:

Hi folks,



My side job as a Python tutor continues to grow.  In two weeks, I
will start working with a high-school student who owns a MacBook
Pro.



So, what other free and lightweight editing options do I have for a
Mac?  I have found a few (fairly old) discussions on
comp.lang.python which suggest Eric
(http://eric-ide.python-projects.org/) and Editra
(http://editra.org/).  Opinions on these and other choices are
appreciated.


Just stumbled upon this
https://github.com/gabrielelanaro/emacs-for-python

Not that I would recommend it if you are not already an emacs user 



---
This email is free from viruses and malware because avast! Antivirus protection 
is active.
http://www.avast.com

--
https://mail.python.org/mailman/listinfo/python-list


Re: How to add a current string into an already existing list

2013-11-02 Thread Denis McMahon
On Sat, 02 Nov 2013 18:25:31 +0200, Nick the Gr33k wrote:

> I just want a mysql column type that can be eligible to store an array
> of elements, a list that is, no need for having a seperate extra table
> for that if we can have a column that can store a list of values.

You'd better take that up with the mysql designers.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Retrieving possible list for use in a subsequent INSERT

2013-11-02 Thread Denis McMahon
On Sat, 02 Nov 2013 02:06:59 +0200, Nick the Gr33k wrote:

> HOW this 'list' is supposed to get stored into the visitors database?

> What colum is able to handle this list?

A python list is a python datatype. mysql has no equivalent data type to 
a python list. You need to convert your python list into a data element 
or elements that mysql understands.

The way I would do it would be to use a table for downloads list where 
each download was linked to the visitor who had downloaded it.

I'm sure all the future users of your torrent search website will be 
pleased to know just how much unnecessary data you are attempting to 
capture about their torrenting activities. When the CIA and the FBI 
persuade the greek government to let them impound your servers, all your 
users worldwide will have their torrenting history laid out in full, 
which I'm sure will please anyone who wishes to litigate against them.

Note also that Greece is part of the EU and that makes your website 
subject to EU data protection requirements. You have to tell your users 
what data you are collecting and storing, and why you are collecting and 
storing it, and you must destroy the data once it is no longer needed.

As an observation, if you are simply providing a torrent search engine, 
you do not need to log or record anything at all.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to add a current string into an already existing list

2013-11-02 Thread Nick the Gr33k

Στις 2/11/2013 3:03 μμ, ο/η Andreas Perstinger έγραψε:

On 02.11.2013 12:58, Nick the Gr33k wrote:

Trying to add the current filename into the existent 'downloads' column
Somehow i don't think i just use the plus sign into an existing column.
We don't try to add numbers here but add an extra string to an already
existing array of strings(list).


[SNIP]


# update specific visitor's download record
cur.execute('''UPDATE visitors SET downloads = downloads + %s WHERE host
= %s''', (filename, host) )
==


Well, when do you understand that your MySQL problems have nothing to do
with Python?

Everything inside the triple quotes is MySQL specific, so it's a MySQL
problem whether you can use + to "add an extra string to an already
existing array of strings(list)".

This list is not a MySQL support forum.

Bye, Andreas



[code]
# find out if visitor had downloaded torrents in the past
cur.execute('''SELECT torrent FROM files WHERE host = %s''', 
host )
data = cur.fetchall()

downloads = []
if data:
for torrent in data:
downloads.append( torrent )
else:
downloads = 'None Yet'

# add this visitor entry into database (host && downloads are 
unique)
		cur.execute('''INSERT INTO visitors (counterID, refs, host, city, 
useros, browser, visits, downloads) VALUES (%s, %s, %s, %s, %s, %s, %s, 
%s)''', (cID, refs, host, city, useros, browser, visits, downloads) )

[/code]

This works bit questios thas arises is what is its difference compare to:

downloads.append( torrent )

Are both these statements create a list?
But in the latter we get the famous:
pymysql.err.InternalError: (1241, 'Operand should contain 1 column(s)')

while in the join() we arent getting this.

I just want a mysql column type that can be eligible to store an array 
of elements, a list that is, no need for having a seperate extra table 
for that if we can have a column that can store a list of values.


--
What is now proved was at first only imagined! & WebHost

--
https://mail.python.org/mailman/listinfo/python-list


Re: multiprocessing: child process race to answer

2013-11-02 Thread Sherard Hall
Thank you for the response. Processing time is very important so I suspect
having to write to disk will take more time than letting the other
processes complete without finding the answer. So I did some profiling one
process finds the answer in about 250ms, but since I can't stop the other
processes, it takes about 800ms before I can use the answer.  Do you
recommend a global variable flag? Any other suggestions?
On Nov 2, 2013 8:17 AM, "William Ray Wing"  wrote:

> On Nov 2, 2013, at 1:03 AM, smhall05  wrote:
>
> > On Friday, November 1, 2013 10:52:40 PM UTC-4, MRAB wrote:
> >> On 02/11/2013 02:35, smhall05 wrote:
> >>
> >>> I am using a basic multiprocessing snippet I found:
> >>>
> >>> #-
> >>> from multiprocessing import Pool
> >>>
> >>> def  f(x):
> >>> return x*x
> >>>
> >>> if __name__ == '__main__':
> >>> pool = Pool(processes=4)  # start 4 worker processes
> >>> result = pool.apply_async(f, [10])# evaluate "f(10)"
> asynchronously
> >>> print result.get(timeout=1)
> >>> print pool.map(f, range(10))  # prints "[0, 1, 4,..., 81]"
> >>> #-
> >>>
> >>> I am using this code to have each process go off and solve the same
> problem, just with different inputs to the problem. I need to be able to
> kill all processes once 1 of n processes has come up with the solution.
> There will only be one answer.
> >>>
> >>> I have tried:
> >>>
> >>> sys.exit(0) #this causes the program to hang
> >>> pool.close()
> >>> pool.terminate
> >>>
> >>
> >> Did you actually mean "pool.terminate", or is that a typo for
> >>
> >> "pool.terminate()"?
> >>
> >>> These still allow further processing before the program terminates.
> What else can I try? I am not able to share the exact code at this time. I
> can provide more detail if I am unclear. Thank you
> >>>
> >
> > I am not sure to be honest, however it turns out that I can't use
> pool.terminate() because pool is defined in main and not accessible under
> my def in which I check for the correct answer.
> > --
> > https://mail.python.org/mailman/listinfo/python-list
>
> So, the simplest solution to that situation is to have whichever
> subprocess that finds the correct answer set a flag which the calling
> process can check.  Depending on your OS, that flag can be anything from
> setting a lock to something as simple as creating a file which the calling
> process periodically wakes up and looks for, maybe just a file in which the
> subprocess has written the answer.
>
> Bill
>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: New to using re. Search for a number before a string.

2013-11-02 Thread Mark Lawrence

On 01/11/2013 21:33, Captain Dunsel wrote:

I have a text file that has lines with numbers occasionally appearing right 
before a person's name.  For example:

COLLEGE:ENROLLMENT:COMPLETED EVALUATIONS:624309FUDD, ELMER

where I want to search for the name "ELMER FUDD" and extract the number right in front of it 
"608309" when such a number appears but the length of the number is variable and using 
?<= in a regular expression will only search for a fixed length.

Any ideas appreciated!



As you've had answers here's some references for future use 
http://docs.python.org/3/howto/regex.html, 
https://wiki.python.org/moin/RegularExpression and 
http://www.regular-expressions.info/python.html


Also, the new regex package is an alternative to the stdlib re package. 
 It's available from https://pypi.python.org/pypi/regex


--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


Re: How to add a current string into an already existing list

2013-11-02 Thread Andreas Perstinger

On 02.11.2013 12:58, Nick the Gr33k wrote:

Trying to add the current filename into the existent 'downloads' column
Somehow i don't think i just use the plus sign into an existing column.
We don't try to add numbers here but add an extra string to an already
existing array of strings(list).


[SNIP]


# update specific visitor's download record
cur.execute('''UPDATE visitors SET downloads = downloads + %s WHERE host
= %s''', (filename, host) )
==


Well, when do you understand that your MySQL problems have nothing to do 
with Python?


Everything inside the triple quotes is MySQL specific, so it's a MySQL 
problem whether you can use + to "add an extra string to an already 
existing array of strings(list)".


This list is not a MySQL support forum.

Bye, Andreas
--
https://mail.python.org/mailman/listinfo/python-list


Re: New to using re. Search for a number before a string.

2013-11-02 Thread Justin Barber
I'm guessing that the name "FUDD, ELMER" varies. In that case, you might try 
something like this:

>>> id_num_regex = re.compile(r'\d+(?=\w+\b,.+?)')
>>> id_num_regex.findall(t)
['624309']

This would account for first names such as 'Mary Ann' and also automatically 
matches characters only to the end of the line, since you have not flagged 
re.DOTALL.

Justin
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: multiprocessing: child process race to answer

2013-11-02 Thread William Ray Wing
On Nov 2, 2013, at 1:03 AM, smhall05  wrote:

> On Friday, November 1, 2013 10:52:40 PM UTC-4, MRAB wrote:
>> On 02/11/2013 02:35, smhall05 wrote:
>> 
>>> I am using a basic multiprocessing snippet I found:
>>> 
>>> #-
>>> from multiprocessing import Pool
>>> 
>>> def  f(x):
>>> return x*x
>>> 
>>> if __name__ == '__main__':
>>> pool = Pool(processes=4)  # start 4 worker processes
>>> result = pool.apply_async(f, [10])# evaluate "f(10)" asynchronously
>>> print result.get(timeout=1)
>>> print pool.map(f, range(10))  # prints "[0, 1, 4,..., 81]"
>>> #-
>>> 
>>> I am using this code to have each process go off and solve the same 
>>> problem, just with different inputs to the problem. I need to be able to 
>>> kill all processes once 1 of n processes has come up with the solution. 
>>> There will only be one answer.
>>> 
>>> I have tried:
>>> 
>>> sys.exit(0) #this causes the program to hang
>>> pool.close()
>>> pool.terminate
>>> 
>> 
>> Did you actually mean "pool.terminate", or is that a typo for
>> 
>> "pool.terminate()"?
>> 
>>> These still allow further processing before the program terminates. What 
>>> else can I try? I am not able to share the exact code at this time. I can 
>>> provide more detail if I am unclear. Thank you
>>> 
> 
> I am not sure to be honest, however it turns out that I can't use 
> pool.terminate() because pool is defined in main and not accessible under my 
> def in which I check for the correct answer.
> -- 
> https://mail.python.org/mailman/listinfo/python-list

So, the simplest solution to that situation is to have whichever subprocess 
that finds the correct answer set a flag which the calling process can check.  
Depending on your OS, that flag can be anything from setting a lock to 
something as simple as creating a file which the calling process periodically 
wakes up and looks for, maybe just a file in which the subprocess has written 
the answer.

Bill

-- 
https://mail.python.org/mailman/listinfo/python-list


How to add a current string into an already existing list

2013-11-02 Thread Nick the Gr33k


Trying to add the current filename into the existent 'downloads' column
Somehow i don't think i just use the plus sign into an existing column.
We don't try to add numbers here but add an extra string to an already 
existing array of strings(list).


==
# update specific torrent's download counter
cur.execute('''UPDATE files SET hits = hits + 1, host = %s, city = %s, 
lastvisit = %s WHERE torrent = %s''', (host, city, lastvisit, filename) )


# update specific visitor's download record
cur.execute('''UPDATE visitors SET downloads = downloads + %s WHERE host 
= %s''', (filename, host) )

==




Retrieval time for displaying purposes:
==
downloads = []
if cur.rowcount:
for torrent in data:
downloads = ', '.join( torrent )
else:
downloads = 'Κανένα κατέβασμα ταινίας'

# add this visitor entry into database (visits is unique)
cur.execute('''INSERT INTO visitors (counterID, refs, host, city, 
useros, browser, visits, downloads) VALUES (%s, %s, %s, %s, %s, %s, %s, 
%s)''', (cID, refs, host, city, useros, browser, visits, downloads) )

==

Is this correct, personally i would just prefer:

for torrent in data:
downloads.append( torrent )

Can you tell me the differenced on these two ways?

Aren't the result of both of them a list?

--
https://mail.python.org/mailman/listinfo/python-list


Re: Retrieving possible list for use in a subsequent INSERT

2013-11-02 Thread Lele Gaifax
Nick the Gr33k  writes:

> sql = '''INSERT INTO visitors (counterID, refs, host, city, useros,
> browser, visits, downloads) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)'''
> % (cID, refs, host, city, useros, browser, visits, downloads)

It was suggested *several* times but I'll reiterate: do not use Python
iterpolation to pass parameters to your SQL statements, or you sooner or
later will hit this kind of problems.

To be clear:

>>> myvalue = "Italy, Europe"
>>> mysql = "INSERT INTO sometable (theid, thevalue) VALUES (%s, %s)" % 
(myid, myvalue)
>>> print(mysql)
INSERT INTO sometable (theid, thevalue) VALUES (theid, Italy, Europe)

ciao, lele.
--
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
l...@metapensiero.it  | -- Fortunato Depero, 1929.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea.

2013-11-02 Thread Antoon Pardon
Op 02-11-13 02:51, ru...@yahoo.com schreef:
> On 11/01/2013 06:50 AM, Antoon Pardon wrote:
>> Op 01-11-13 05:41, ru...@yahoo.com schreef:
>>> On 10/31/2013 02:41 AM, Steven D'Aprano wrote:
>>>
 I don't know whether you are deliberately lying, or whether you're just 
 such a careless reader that you have attributed words actually written by 
 Skybuck to me, but either way I expect an apology from you for putting 
 false words into my mouth.
>>>
>>> An apology is due when someone does some damage to things 
>>> or people (including reputation or feelings) that should 
>>> have been avoided.
>>>
>>> My overstating your disagreement with Skybuck was inadvertent, 
>>> does not change the points I was making (it does not matter 
>>> whether you thought he was wrong or nutty) and did no 
>>> significant damage to you or your reputation.  
>>
>> It seems rather obvious from Steven's reaction, your overstatement
>> hurt (damaged) his feelings. 
> 
> It it not obvious to me at all.

Shouldn't you be erring on the safe side? Rather issue an appology
when it may not be really needed than refuse to give one when it
may be appropiate?

>> Since you ackowleged that damaged
>> feelings are cause for an apology, it seems by your own words
>> an apology is due.
> 
> I explained why an apology was not appropriate previously.

No you didn't. What you did was trying to minimize your contribution.

-- 
Antoon Pardon

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Retrieving possible list for use in a subsequent INSERT

2013-11-02 Thread Nick the Gr33k

You can see the erro as its appearing here:

http://superhost.gr/

Its weird that no single quotes are enclosing the string values though 
and the other bizarre thign is that 'downloads' list is tryign to fiull 
in all the movies.

--
https://mail.python.org/mailman/listinfo/python-list


Re: Python on a MacBook Pro (not my machine)

2013-11-02 Thread rusi
On Sunday, October 27, 2013 12:37:40 AM UTC+5:30, John Ladasky wrote:
> Hi folks,

> My side job as a Python tutor continues to grow.  In two weeks, I
> will start working with a high-school student who owns a MacBook
> Pro.

> So, what other free and lightweight editing options do I have for a
> Mac?  I have found a few (fairly old) discussions on
> comp.lang.python which suggest Eric
> (http://eric-ide.python-projects.org/) and Editra
> (http://editra.org/).  Opinions on these and other choices are
> appreciated.

Just stumbled upon this
https://github.com/gabrielelanaro/emacs-for-python

Not that I would recommend it if you are not already an emacs user
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Retrieving possible list for use in a subsequent INSERT

2013-11-02 Thread Nick the Gr33k

Στις 2/11/2013 4:00 πμ, ο/η ru...@yahoo.com έγραψε:

On Friday, November 1, 2013 9:04:08 AM UTC-6, Ferrous Cranus wrote:

Rurpy can you help me please solve this?
is enum or set column types what needed here as proper columns to store
'download' list?


I'd help if I could but I don't use MySql and don't know anything
about its column types.  All I could do it try to read about it
(which I don't have time for right now) and you know more about
it than me so you can probably figure it out more quickly.




Okey here is some improvement:

Splitting the statement in 3 steps to print it before actually executing iy.

=
sql = '''INSERT INTO visitors (counterID, refs, host, city, useros, 
browser, visits, downloads) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)''' % 
(cID, refs, host, city, useros, browser, visits, downloads)

print repr(sql)
cur.execute(sql)
=

This the real time values trying to be passed into MySQL table in python 
script's runtime


=
"INSERT INTO visitors (counterID, refs, host, city, useros, browser, 
visits, downloads) VALUES (1, Χωρίς Referrer - Άμεσο Hit, 
46-198-103-93.adsl.cyta.gr, Europe/Athens, Windows, Chrome, 13-11-02 
10:31:29, [('Jobs.2013. WEBRip XViD juggs',), 
('Pacific.Rim.2013.720p.BDRip.XviD.AC3-ELiTE',), ('Man of Steel 2013 
BRRip XviD AC3-SANTi',), ('Now You See Me EXTENDED 2013 BRRip XviD 
AC3-SANTi',), ('DAS EXPERIMENT (2001) 720p.BDRip.XVID.AC3',), ('Behind 
the Candelabra 2013 BDrip XviD AC3',), 
('The.Internship.2013.UNRATED.480p.BRRip.Xvid.AC3',), ('Man Of Tai 2013 
WEBrip XVID AC3',), ('Star Trek Into Darkness 2013 BRRip XviD 
AC3-SANTi',), ('ESCAPE PLAN (2013) CAM XViD UNiQUE',)])"


ProgrammingError(ProgrammingError(1064, "You have an error in your SQL 
syntax; check the manual that corresponds to your MySQL server version 
for the right syntax to use near 'Referrer - Άμεσο Hit, 
46-198-103-93.adsl.cyta.gr, Europe/Athens, Windows, C' at line 1"),)

=

The definition of 'visitro's table is as follows:

=
create table visitors
(
  counterID integer(5) not null,
  host varchar(50) not null,
  refs varchar(25) not null,
  city varchar(20) not null,
  userOS varchar(10) not null,
  browser varchar(10) not null,
  hits integer(5) not null default 1,
  visits datetime not null,
  download text not null,
  foreign key (counterID) references counters(ID),
  unique index (visits)
 )ENGINE = MYISAM;
=

It is possible to "just" use a VARCHAR or TEXT field and then add 
anything you want to it, including a comma or semi-colon separated list.

--
https://mail.python.org/mailman/listinfo/python-list


Re: Testing python command line apps -- Running from within the projects w/o installing

2013-11-02 Thread Göktuğ Kayaalp
> [...]
> Testing at levels of abstraction above the unit is important, but
> Python's ‘unittest’ is not a good fit. You'll need a different tool.
>
> For behaviour testing, I recommend Behave, which lets you describe
> assertions in English and have them automatically tested
> https://pypi.python.org/pypi/behave/>.
> 
> For integration testing, I recommend an automated build system like
> Jenkins http://jenkins-ci.org/> which can get your full source
> tree, build it using your build system, and run all your arbitrary test
> commands.
> 
> For running arbitrary commands as tests, you might be interested in
> Atheist http://arco.esi.uclm.es/~david.villa/atheist/html/>. I
> haven't tried it.
> 

Thank you Ben!  I would never find these until I was desparate to do so.
Also, via these links, I have found pointers to many other useful things
too, namely behave4cmd (incubating, no code) and django-behave.

> > I write a secondary script, 'app_tester', which is similar to 'app',
> > but before running app.main.main, it inserts ~/app to the front of
> > sys.path.
> 
> I think that's a poor solution. It's the worst of both worlds: you have
> a special-case tool, but one that doesn't actually test the application
> properly since it's not a very accurate representation of how the
> application will actually be installed. Better is simply using the build
> system to do a real, temporary install, and running the tests in there.
> 

Yes, I better use virtualenvs for their purpose. I'll think of "edit -
install to virtualenv - test" cycle as "edit - compile - run" cycle for
AOT-compiled languages from now on.  Or maybe I will use CI tools to
automate this, but I am to alien to CI to assert anything.

> -- 
>  \“Odious ideas are not entitled to hide from criticism behind |
>   `\  the human shield of their believers' feelings.” —Richard |
> _o__) Stallman |
> Ben Finney
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list


signature.asc
Description: Digital signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: New to using re. Search for a number before a string.

2013-11-02 Thread Jussi Piitulainen
Captain Dunsel writes:

> I have a text file that has lines with numbers occasionally
> appearing right before a person's name.  For example:
> 
> COLLEGE:ENROLLMENT:COMPLETED EVALUATIONS:624309FUDD, ELMER
> 
> where I want to search for the name "ELMER FUDD" and extract the
> number right in front of it "608309" when such a number appears but
> the length of the number is variable and using ?<= in a regular
> expression will only search for a fixed length.
> 
> Any ideas appreciated! 

Search for the digits and the name together. Make the digits a group
by putting their pattern in parentheses. If there is a match object,
extract the group.

 >>> line = 'COLLEGE:ENROLLMENT:COMPLETED EVALUATIONS:624309FUDD, ELMER'
 >>> m = re.search(r':(\d*)ELMER FUDD$', line)
 >>> m.group(1) if m else 'not found'
 'not found'
 >>> m = re.search(r':(\d*)FUDD, ELMER$', line)
 >>> m.group(1) if m else 'not found'
 '624309'

If you want a match only when there are digits, use \d+ instead.

Look at regex.search and match.group here:

-- 
https://mail.python.org/mailman/listinfo/python-list