Pydev 1.3.0 Released
Hi All, Pydev and Pydev Extensions 1.3.0 have been released Details on Pydev Extensions: http://www.fabioz.com/pydev Details on Pydev: http://pydev.sf.net Details on its development: http://pydev.blogspot.com Release Highlights in Pydev Extensions: - * Find References: Ctrl+Shift+G can be used to find the references to the selected token in the editor * Fix: Code-analysis: Fixed false positive for statement with no effect Release Highlights in Pydev: -- * Code-completion: Deep analysis for discovering arguments in constructs 'from imports' now can be configured given the number of chars of the qualifier * Refactoring for override methods: changed so that it uses the pydev code-completion engine for getting the hierarchy and methods * Fix: Python Nature Restore: begin rule does not match outer scope rule fixed * Fix: Package Explorer: if show-in is in a deep structure, it will show it is the 1st try and not only in the 2nd * Fix: Package Explorer: some intercepts removed elements incorrectly, and ended up messing the navigator and search (which has 'null' elements because of that) What is PyDev? --- PyDev is a plugin that enables users to use Eclipse for Python and Jython development -- making Eclipse a first class Python IDE -- It comes with many goodies such as code completion, syntax highlighting, syntax analysis, refactor, debug and many others. Cheers, -- Fabio Zadrozny -- Software Developer ESSS - Engineering Simulation and Scientific Software http://www.esss.com.br Pydev Extensions http://www.fabioz.com/pydev Pydev - Python Development Enviroment for Eclipse http://pydev.sf.net http://pydev.blogspot.com -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: Watching a file another app is writing
Nick Vatamaniuc wrote: You might need to look at pywin32 for Windows specific ways to listen to file changed event. On Unix a quick shortcut would be to simply read the output of 'tail - f file' command... Ah, I forgot I have Cygwin installed, so I do have tail. Unfortunately Windows will not let most programs save to the file while tail is watching it, and when I force it with vim :w! the output from tail -f does not update. Maybe I'm using it wrong. Well, off to dig through windows documentation. Then I have to figure out how to write and event loop for the shell. -- http://mail.python.org/mailman/listinfo/python-list
using python to visit web sites and print the web sites image to files
Hi there, I wonder whether python can be used to simulate a real user to do the following: 1) open a web site in a browser; 2) printscreen, so to copy the current active window image to clipboard; 3) save the image file to a real file Any pointer will be apprieciated! Xiong -- http://mail.python.org/mailman/listinfo/python-list
can not load mod_python on apache
winxp sp2 modpython 3.3.1 apache 2.2.4 python 2.5 when i start apache ,it failed. and the error is == The Apache service named reported the following error: httpd.exe: Syntax error on line 166 of F:/mylg/apache-more/local/apache/Apache2/conf/httpd.conf: Cannot load F:/mylg/apache-more/local/apache/Apache2/modules/mod_python.so into server: \xd5\xd2\xb2\xbb\xb5\xbd\xd6\xb8\xb6\xa8\xb5\xc4\xc4\xa3\xbf\xe9\xa1\x . === who can help me?? -- http://mail.python.org/mailman/listinfo/python-list
Re: Putting Metaclasses to Work
On Mar 11, 7:31 pm, Alan Isaac [EMAIL PROTECTED] wrote: Forman's book is out of print. Is there a good substitute? Thanks, Alan Isaac The book is about a non-standard implementation of C++ featuring metaclasses. It it not that relevant if you are interested in metaclasses in Python. You can find lots of info about metaclasses in the Python Wiki. For instance, you can look at http://www.python.org/pycon/dc2004/papers/24/metaclasses-pycon.pdf which has lots of examples. If you insist in wanting the book, you should look for used books. This is the way I bought it from Amazon 5 years ago (dunno if it is still available now, but you never know). Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list
Re: UTF-8
On Sat, 10 Mar 2007 15:00:04 +0100, Olivier Verdier [EMAIL PROTECTED] wrote: [snip] The default encoding i wish to set is UTF-8 since it encodes unicode and is nowadays the standard encoding. I can't agree with that: there are still many tools completely ignoring the encoding problem, and just saving sequences of bytes for any text. This results in letting the current OS deciding what encoding is used, and this is still not always UTF-8. Just consider how many web pages are still encoded in a local encoding without even any specification of what it may be in the HTML header, or how many times you see a [?] or a black square replacing a character in newsgroups or mailing lists. UTF-8 *should* be the standard encoding, but certainly isn't... Having ascii as a default encoding is a pretty strange choice since ascii encodes only 127 characters (suitable only for English, without fancy symbols like €) whereas utf-8 encodes virtually infinitely many characters (suitable for all languages). Besides, utf-8 is a superset of ascii so having it by default won't harm anything. On the contrary, it's IMHO a very sensible thing to do: any character with a code 127 could be in any encoding. So supposing an encoding would be guessing, and part of the Python Zen is: in the face of ambiguity, refuse the temptation to guess. The problem is here that if the encoding is not UTF-8, things can seem to work, but give completely wrong results. So the decision was apparently to use the minimal common set for everything, which is ASCII; this seems quite logical to me. (BTW, one could even argue that the default encoding should be non-existent, as I think there are some non-latin encodings that do not even include ASCII [I think I saw a Chinese encoding like that one day...]. So even supposing that ASCII will work is sometimes wrong...) At the very least there should be a configuration file that allows to set a default encoding (although setting anything else than utf-8 should be advised against). Such a feature would be greatly appreciated by all of us non native English speakers around the world. Well, I *am* a non-native English speaker, and after the first why should I bother about all this encoding stuff? period, which seems to happen to everybody, I finally understood the logic behind Python choices, and why I *should* bother about encodings. Whatever the default encoding is, and whatever you do, encodings will still be a problem for some time. The transition phase from local encodings to universal ones is likely to last a few years more, if not a few decades... HTH -- python -c print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-']) -- http://mail.python.org/mailman/listinfo/python-list
New to Python
Hi, I am new to Python, how stupid can be the questions I ask? For example, how can I add (mathematically) two tuples? x = (1,2) y = (3,4) How can I get z = (1 + 3, 2 + 4) ? Alberto Monteiro -- http://mail.python.org/mailman/listinfo/python-list
Re: New to Python
On Mar 12, 3:02 am, Alberto Vieira Ferreira Monteiro [EMAIL PROTECTED] wrote: Hi, I am new to Python, how stupid can be the questions I ask? For example, how can I add (mathematically) two tuples? x = (1,2) y = (3,4) How can I get z = (1 + 3, 2 + 4) ? Alberto Monteiro Alberto - List comprehesion, no doubt about it: z = [k+p for k,p in (x, y)] z [3, 7] - Bert -- http://mail.python.org/mailman/listinfo/python-list
Re: New to Python
Alberto Vieira Ferreira Monteiro [EMAIL PROTECTED] writes: Hi, I am new to Python, how stupid can be the questions I ask? Well, it's a matter of how you ask them, but anyway newcomers are welcome here. For example, how can I add (mathematically) two tuples? x = (1,2) y = (3,4) How can I get z = (1 + 3, 2 + 4) ? The simplest way is explicitly: z = (x[0]+y[0], x[1]+y[1]) There's not a really direct way to do it. Tuples aren't vectors. Python does support complex numbers if that's what you want: x = 1+2j # Python uses j for sqrt(-1) y = 3+4j z = x + y print z -- http://mail.python.org/mailman/listinfo/python-list
Re: Watching a file another app is writing
En Mon, 12 Mar 2007 04:25:48 -0300, Gordon Airporte [EMAIL PROTECTED] escribió: Nick Vatamaniuc wrote: You might need to look at pywin32 for Windows specific ways to listen to file changed event. This article explains it in detail: http://tgolden.sc.sabren.com/python/win32_how_do_i/watch_directory_for_changes.html BTW, it's the top result on Google for python notify file change windows -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Are Lists thread safe?
Gabriel Genellina [EMAIL PROTECTED] wrote: INPLACE_ADD would call MyList.__iadd__ which you have wrapped. But you have a race condition between that moment and the following STORE_ATTR, a context switch may happen in the middle. It may not be possible to create an absolutely thread-safe list without some help on the client side. (Comments, someone?) The list itself can be thread safe quite easily, but if the namespace from which you reference it is shared between threads you would have to protect the namespace as well, or avoid using in-place operators. The rebinding is a mutation on the namespace rather than the object, so that is what you have to protect. -- http://mail.python.org/mailman/listinfo/python-list
Re: Watching a file another app is writing
Gordon Airporte schreef: Nick Vatamaniuc wrote: You might need to look at pywin32 for Windows specific ways to listen to file changed event. On Unix a quick shortcut would be to simply read the output of 'tail - f file' command... Ah, I forgot I have Cygwin installed, so I do have tail. Unfortunately Windows will not let most programs save to the file while tail is watching it, and when I force it with vim :w! the output from tail -f does not update. Maybe I'm using it wrong. Have you tried with tail -F instead of tail -f? With a big F it uses the name of the file instead of the file descriptor, and it keeps trying to open the file. I'm not sure if it will work, but it's worth a shot. -- If I have been able to see further, it was only because I stood on the shoulders of giants. -- Isaac Newton Roel Schroeven -- http://mail.python.org/mailman/listinfo/python-list
Re: Weekly Python Patch/Bug Summary
Kurt B. Kaiser schrieb: Patch / Bug Summary ___ Patches : 380 open (-36) / 3658 closed (+65) / 4038 total (+29) We should really try to keep the numbers in this magnitude :) Georg -- http://mail.python.org/mailman/listinfo/python-list
Re: distributed queue?
On 2007-03-10, Paul Rubin http wrote: Does anyone have an implementation of a distributed queue? I.e. I have a long running computation f(x) and I'd like to be able to evaluate it (for different values of x) on a bunch of different batchlib and the underlying exec_proxy are designed to handle exactly this type of problem. Both of them are in PyPI (and available at my site http://se.wtb.tue.nl/~hat). Alnert -- http://mail.python.org/mailman/listinfo/python-list
Re: New to Python
Bert Heymans schrieb: On Mar 12, 3:02 am, Alberto Vieira Ferreira Monteiro [EMAIL PROTECTED] wrote: Hi, I am new to Python, how stupid can be the questions I ask? For example, how can I add (mathematically) two tuples? x = (1,2) y = (3,4) How can I get z = (1 + 3, 2 + 4) ? Alberto Monteiro Alberto - List comprehesion, no doubt about it: z = [k+p for k,p in (x, y)] z [3, 7] - Bert Since 1+3 is not really (only if you use rally bad approximations) 3 (neither 2+4 is 7!), i'd rather prefer using zip: x = (1,2) y = (3,4) [k+p for k,p in (x,y)] # wrong one [3, 7] [k+p for k,p in zip(x,y)] # zip-version [4, 6] What your's is doing is unpacking the contents of x first to k and p and adding them to each other and afterwards doing the same with y's contents. -- http://mail.python.org/mailman/listinfo/python-list
Using .NET COM-objects and GetType
Hi. I need to dynamically retreive the type name of a COM-object exposed by a C# COM server. This was previously successfully done in .NET framwork 1.X with the method GetType(), inherited by all classes from System.Object. Moving to .NET framework 2.0, it stopped working. All I get from GetType() is a PyIUnknown that has no IDispatch interface. Cannot understand how to get it working. Appreciate any help. Thanks! /nevS -- http://mail.python.org/mailman/listinfo/python-list
Re: New to Python
Alberto Vieira Ferreira Monteiro wrote: Hi, I am new to Python, how stupid can be the questions I ask? For example, how can I add (mathematically) two tuples? x = (1,2) y = (3,4) How can I get z = (1 + 3, 2 + 4) ? Others have shown you ways to accomplish this, and stated correctly that tuples aren't vectors. You can also go and look into Numpy, the python numerical package. That let's you do lots of operations on vectors and matrices. Diez -- http://mail.python.org/mailman/listinfo/python-list
programmatically manipulation environment variables of the calling shell
Hello list, I'm trying to write a python script that would allow me to manipulate shell variables of the calling shell. I'm trying to write some logic that would know to add LD_LIBRARY_PATH to the users environment. In bash this is done with export, can I do this with python? (If at all possible because python is actually a sub process of bash). Thank you, Maxim. -- Cheers, Maxim Veksler Free as in Freedom - Do u GNU ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Object instance reporting to a container class instance
Daniel Lipovetsky wrote: I would like for an object to report to a container object when a new instance is created or deleted. I could have a container object that is called when a new instance is created, as below. I've run into a similar problem before, in my case it was easiest to allow the container to create the new instances, sort of like: CODE class Something(object): def __init__(self, *args): self.x=args class Container(object): def __init__(self): self.instances=[] def newinstance(self, newclass, *args): tmp=newclass(args) self.instances.append(tmp) return tmp def delinstance(self, inst): self.instances.remove(inst) cont=Container() a=cont.newinstance(Something, 5, 6) b=cont.newinstance(Something, 7, 8) c=cont.newinstance(Something, 8, 9) print len(cont.instances) cont.delinstance(b) print len(cont.instances) #note that b is still defined, unless you remove that name explicitly... print b del b print b /CODE This can be very, very, very ugly. I don't particularly actually recommend doing anything like this. Usually you should re-think your organization to make this unnecessary. I suppose, though, it can come in handy in certain situations. -Jordan G -- http://mail.python.org/mailman/listinfo/python-list
Re: programmatically manipulation environment variables of the calling shell
Maxim Veksler wrote: Hello list, I'm trying to write a python script that would allow me to manipulate shell variables of the calling shell. I'm trying to write some logic that would know to add LD_LIBRARY_PATH to the users environment. In bash this is done with export, can I do this with python? (If at all possible because python is actually a sub process of bash). It's not possible, OS restrictions - you are not allowed to alter the environment of a parent process. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: can not load mod_python on apache
liecto a écrit : winxp sp2 modpython 3.3.1 apache 2.2.4 python 2.5 when i start apache ,it failed. and the error is == The Apache service named reported the following error: httpd.exe: Syntax error on line 166 of F:/mylg/apache-more/local/apache/Apache2/conf/httpd.conf: Cannot load F:/mylg/apache-more/local/apache/Apache2/modules/mod_python.so into server: \xd5\xd2\xb2\xbb\xb5\xbd\xd6\xb8\xb6\xa8\xb5\xc4\xc4\xa3\xbf\xe9\xa1\x . === who can help me?? Someone on either apache or mod_python mailing lists ? (you problem is about apache conf, not Python). -- http://mail.python.org/mailman/listinfo/python-list
Re: New to Python
I wrote: Hi, I am new to Python, how stupid can be the questions I ask? For example, how can I add (mathematically) two tuples? x = (1,2) y = (3,4) How can I get z = (1 + 3, 2 + 4) ? Wow, I really didn't expect that my silly little newbie question would get so many _different_ answers! What is the best way to get documentation about the functions and classes of python? I tried to google, but usually I can just find the __doc__ of the objects, without examples or anything that can help me use it. Alberto Monteiro -- http://mail.python.org/mailman/listinfo/python-list
Re: programmatically manipulation environment variables of the calling shell
On Mar 12, 11:33 am, Maxim Veksler [EMAIL PROTECTED] wrote: Hello list, I'm trying to write a python script that would allow me to manipulate shell variables of the calling shell. I'm trying to write some logic that would know to add LD_LIBRARY_PATH to the users environment. In bash this is done with export, can I do this with python? (If at all possible because python is actually a sub process of bash). The Popen class from the subprocess module takes an optional 'env' parameter, which defines environment variables for the child process created by Popen, if that helps. Gerard -- http://mail.python.org/mailman/listinfo/python-list
Re: number generator
[EMAIL PROTECTED] (Alex Martelli) wrote: Without any specification regarding the distributions required for the 5 random numbers it's really impossible to say whether these are better or worse than other proposed solutions. FWIW, I decided it would be fun to see what kind of implementation I could come up test driven and avoiding reading the thread or background references too much first. So starting from: import unittest def partition(total, n, min): return [50] class PartitionTests(unittest.TestCase): def testsinglevalue(self): self.assertEqual([50], partition(50, 1, 1)) if __name__=='__main__': unittest.main() I eventually worked my way through 15 revisions to the code below. The tests were added in the order you see them below. The commented out function is the one I had arrived at before I added the first distribution test which triggered a major refactor (although the code ended up remarkably similar): if you uncomment it all but the distribution tests pass. I don't really like the arbitrary limits for the distribution tests, but I'm not sure how else to test that sort of thing. And as Alex said, without knowing what distribution the OP wanted the definition I chose to use is completely arbitrary. - partition.py --- import unittest, collections from random import randint, sample def partition(total, n, min): maxtotal = total - n*(min-1) posts = sorted(sample(xrange(1, maxtotal), n-1)) return [ (b-a)+min-1 for (a,b) in zip([0]+posts, posts+[maxtotal]) ] # def partition(total, n, min): # maxtotal = total - (n*min) # sums = sorted(randint(0, maxtotal) for i in range(n-1)) # return [(b-a)+min for (a,b) in zip([0]+sums, sums+[maxtotal])] class PartitionTests(unittest.TestCase): def testsinglevalue(self): self.assertEqual([50], partition(50, 1, 1)) def testnvalues(self): self.assertEqual([1]*5, partition(5, 5, 1)) def testnminusone(self): self.assertEqual([1]*4+[2], sorted(partition(6, 5, 1))) def testnminusone2(self): # Check we get all possible results eventually expected = set([(1,1,2), (1,2,1), (2,1,1)]) for i in range(100): got = tuple(partition(4,3,1)) if got in expected: expected.remove(got) if not len(expected): break self.assertEqual(len(expected), 0) def testdistribution(self): # Make sure we get each of 3 possible outcomes roughly # equally often. actual = collections.defaultdict(int) for i in range(1000): actual[tuple(partition(4,3,1))] += 1 counts = actual.values() assert (min(counts) 250) assert (max(counts) 400) def testdistribution2(self): # More arbitrary limits for the distribution. 10 possible # outcomes this time. actual = collections.defaultdict(int) ntries = 1 for i in range(ntries): actual[tuple(partition(6,3,1))] += 1 counts = actual.values() assert (min(counts) 900) assert (max(counts) 1100) def testmintwo(self): self.assertEqual([2]*50, partition(100,50,2)) def testminzero(self): self.assertEqual([0]*20, partition(0,20,0)) def testcantdoit(self): self.assertRaises(ValueError, partition, 100, 51, 2) if __name__=='__main__': unittest.main() -- -- http://mail.python.org/mailman/listinfo/python-list
Re: programmatically manipulation environment variables of the calling shell
On 12 mar 2007, at 11.33, Maxim Veksler wrote: Hello list, I'm trying to write a python script that would allow me to manipulate shell variables of the calling shell. I'm trying to write some logic that would know to add LD_LIBRARY_PATH to the users environment. In bash this is done with export, can I do this with python? (If at all possible because python is actually a sub process of bash). Thank you, Maxim. This is not possible to do directly. There is however a possibility to solve this problem under special circumstances. 1. Your python (/perl/shell/etc) script must write the wanted environment variables to standard out, as key-value pairs with a suitable separator. 2. The invoking shell must agree with your script as to what separator is used. 3. In the calling shell do myshellvars=`your_python_script`; 4. Now the calling shell can parse the variable myshellvars to set up the environment. -- What is a woman that you forsake her, and the hearth fire and the home acre, to go with the old grey Widow Maker. --Kipling, harp song of the Dane women Tommy Nordgren [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: programmatically manipulation environment variables of the calling shell
On 3/12/07, Tommy Nordgren [EMAIL PROTECTED] wrote: On 12 mar 2007, at 11.33, Maxim Veksler wrote: Hello list, I'm trying to write a python script that would allow me to manipulate shell variables of the calling shell. I'm trying to write some logic that would know to add LD_LIBRARY_PATH to the users environment. In bash this is done with export, can I do this with python? (If at all possible because python is actually a sub process of bash). Thank you, Maxim. This is not possible to do directly. There is however a possibility to solve this problem under special circumstances. 1. Your python (/perl/shell/etc) script must write the wanted environment variables to standard out, as key-value pairs with a suitable separator. 2. The invoking shell must agree with your script as to what separator is used. 3. In the calling shell do myshellvars=`your_python_script`; 4. Now the calling shell can parse the variable myshellvars to set up the environment. Yes, thats exactly what I was set to do. bash for export_val in $(python env_variables_maxim.py); do export $export_val; done python (env_variables_maxim.py) print 'FOO=123 BAR=/home/src:$BAR PATH=/nfs/bin' Thank you. -- What is a woman that you forsake her, and the hearth fire and the home acre, to go with the old grey Widow Maker. --Kipling, harp song of the Dane women Tommy Nordgren [EMAIL PROTECTED] -- Cheers, Maxim Veksler Free as in Freedom - Do u GNU ? -- http://mail.python.org/mailman/listinfo/python-list
Re: number generator
Paul Rubin http wrote: The fencepost method still seems to be simplest: t = sorted(random.sample(xrange(1,50), 4)) print [(j-i) for i,j in zip([0]+t, t+[50])] Mmm, nice. Here is another effort which is easier to reason about the distribution produced but not as efficient. def real(N, M): while 1: t = [ random.random() for i in range(N) ] factor = M / sum(t) t = [ int(round(x * factor)) for x in t] if sum(t) == M: break print again assert len(t) == N assert sum(t) == M return t It goes round the while loop on average 0.5 times. If 0 isn't required then just test for it and go around the loop again if found. That of course skews the distribution in difficult to calculate ways! -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list
Re: Bitpacked Data
none wrote: i need to interface python with a bitpacked data file, the structure recorded in the file is the following: struct { var_1 4bit var_2 6bit var_3 2bit var_3 4bit } how can read the struct and convert data into dictionary You could try Construct http://construct.wikispaces.com/ This allows you to build a python class which will translate to and from that datastructure. -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list
Re: How to modify the source of a python file inside a python egg file?
[EMAIL PROTECTED] wrote: How to modify the source of a python file inside a python egg file? I can see the file by unzipping it, but how can I package it back as a python egg file after my modification. So far I never tried this - but how about zipping it? Besides, you can install eggs unzipped directly, try easy_install --help for options. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: programmatically manipulation environment variables of the calling shell
Hello, On Mon, Mar 12, 2007 at 11:40:11AM +0100, Diez B. Roggisch wrote: Maxim Veksler wrote: I'm trying to write a python script that would allow me to manipulate shell variables of the calling shell. I'm trying to write some logic that would know to add LD_LIBRARY_PATH to the users environment. It's not possible, OS restrictions - you are not allowed to alter the environment of a parent process. Actually, you are able to modify only your own environment (and call a new process with any possible environment). And the restrictions seem to me rather technical - the process would have to change its behaviour each time it changes. With regards -- grep me no patterns and I'll tell you no lines. Michal 'vorner' Vaner pgpiWqB4iIas1.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: programmatically manipulation environment variables of the calling shell
Michal 'vorner' Vaner wrote: Hello, On Mon, Mar 12, 2007 at 11:40:11AM +0100, Diez B. Roggisch wrote: Maxim Veksler wrote: I'm trying to write a python script that would allow me to manipulate shell variables of the calling shell. I'm trying to write some logic that would know to add LD_LIBRARY_PATH to the users environment. It's not possible, OS restrictions - you are not allowed to alter the environment of a parent process. Actually, you are able to modify only your own environment (and call a new process with any possible environment). And the restrictions seem to me rather technical - the process would have to change its behaviour each time it changes. Not only technical - they are important security-wise - you could try and make a parent process use a modified library that would e.g. authenticate users without passwords. Diez -- http://mail.python.org/mailman/listinfo/python-list
Single string print statements on multiple lines.
In my 100 level CS course, I was asked to create multiple lines of output within a single string. Of course I know how to: print I am print a python print newbie. How can I get this accomplished using a single string (assuming this means a one line statement). Is there and escape character or something that could be added? Thanks for any help that can be provided. -- http://mail.python.org/mailman/listinfo/python-list
Re: Single string print statements on multiple lines.
HeEm wrote: In my 100 level CS course, I was asked to create multiple lines of output within a single string. Of course I know how to: print I am print a python print newbie. How can I get this accomplished using a single string (assuming this means a one line statement). Is there and escape character or something that could be added? Thanks for any help that can be provided. The usual one: \ Do first line\nnextline Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: setuptools and code.google.com
[EMAIL PROTECTED] (Alex Martelli) writes: Hey, I'd just love to make it as easy as possible to get gmpy -- that's why I (shudder!-) even build and upload Windows installers... Brave man! :-) OK, the .zip file IS there -- I don't know how to build .egg ones but of course I could study up on it -- can you suggest a URL? The .egg is nice because it can be an already built binary. http://peak.telecommunity.com/DevCenter/setuptools The URL above contains examples and instructions on how to use setuptools. To be usable on Windows w/o effort, the packaged format must contain a .pyd (and, on Mac, a .so, etc). Can a .egg deal w/that? Yes. I have a .egg that has a .so here, for rpy (http://rpy.sf.net/). I need to find out w/certainty, because once I've uploaded a file w/a certain name I can't change the name, nor the contents -- the URLs on code.google.com are meant to be permanent... Hmmm... I'd suggest you to build only locally then... I don't like this kind of permanent things. They could have a flag publish this to make it permanent and make the standard unpublished. Here's a suggestion for you to forward there inside Google... ;-) OK, but since most Windows users don't have a suitable C compiler, and many Mac ones never bother installing the C compiler that comes with their OS DVDs, if I'm to make things easy I definitely need to pack up binaries. How do I pack binaries (for dynamic link libraries) that need to be very different on Win, Mac, various Linux distros...? One build per platform would be my choice. Packing everything together would make the package too big (specially if you start supporting other OSs). Me neither, knowing near to nothing about setuptools (I'm not even a user of it...). Let's hope some expert does speak up -- I can't just freely experiment with uploads and the like... Lets wait. ;-) Thanks again, -- Jorge Godoy [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: How to modify the source of a python file inside a python egg file?
[EMAIL PROTECTED] [EMAIL PROTECTED] writes: How to modify the source of a python file inside a python egg file? I can see the file by unzipping it, but how can I package it back as a python egg file after my modification. The correct way is to download the source, make your changes and rebuild the egg. Unzipping, changing and zipping it back also works. -- Jorge Godoy [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: New to Python
Alberto Vieira Ferreira Monteiro escreveu: Hi, I am new to Python, how stupid can be the questions I ask? For example, how can I add (mathematically) two tuples? x = (1,2) y = (3,4) How can I get z = (1 + 3, 2 + 4) ? Alberto Monteiro I think that what you want is numpy. I don't know too much about it but a possible solution is: import numpy x=numpy.array([1,2]) y=numpy.array([3,4]) z=x+y Now z is an array containing 4,6. You may convert it to list or tuple z=list(z) -- http://mail.python.org/mailman/listinfo/python-list
Re: Single string print statements on multiple lines.
HeEm wrote: In my 100 level CS course, I was asked to create multiple lines of output within a single string. Of course I know how to: If this is for a CS course, you shouldn't really be cheating and asking for an answer here, should you? I mean, the whole point of taking (and paying for!) a CS course is to learn CS, right? But like Diez said, the standard C escapes work in python: \t = TAB, \r = CARRIAGERETURN, \n = NEWLINE/LINEFEED, c. Regards, Jordan -- http://mail.python.org/mailman/listinfo/python-list
Re: New to Python
On Mar 12, 5:07 am, Alberto Monteiro [EMAIL PROTECTED] wrote: I wrote: Hi, I am new to Python, how stupid can be the questions I ask? For example, how can I add (mathematically) two tuples? x = (1,2) y = (3,4) How can I get z = (1 + 3, 2 + 4) ? Wow, I really didn't expect that my silly little newbie question would get so many _different_ answers! What is the best way to get documentation about the functions and classes of python? I tried to google, but usually I can just find the __doc__ of the objects, without examples or anything that can help me use it. Alberto Monteiro Refer to this as a reference: http://docs.python.org/ It includes a tutorial and documentation on the functions and classes in all the global modules, as well as builtin functions (http:// docs.python.org/lib/built-in-funcs.html) and syntax. If you have prior experience with programming, you may be able to learn python from the tutorial, but otherwise, I would highly recommend you get a good book for beginners on python (http://wiki.python.org/moin/PythonBooks); there's plenty of them out there. -- http://mail.python.org/mailman/listinfo/python-list
Re: New to Python
Dustan wrote: What is the best way to get documentation about the functions and classes of python? I tried to google, but usually I can just find the __doc__ of the objects, without examples or anything that can help me use it. Refer to this as a reference: http://docs.python.org/ I guess I've been there :-) It includes a tutorial and documentation on the functions and classes in all the global modules, as well as builtin functions (http:// docs.python.org/lib/built-in-funcs.html) and syntax. If you have prior experience with programming, you may be able to learn python from the tutorial, but otherwise, I would highly recommend you get a good book for beginners on python (http://wiki.python.org/moin/PythonBooks); there's plenty of them out there. I do have previous experience with programming (much more than it's reasonable for one lifetime, BTW. I have the curse of never forgetting things I learn, so sometimes I catch myself thinking in archaic and extinct languages), but I found python particularly hard to learn (not as much as Haskell). Maybe I am not doing it the right way, trying to learn Python _and_ Python GUI interface at the same time. For example, yesterday I wanted to open a window, draw some image, and make it move. I tried it with tkinter and with pygame, but I didn't succeed - there was no way I could find how to begin the image in the center of the window (!!!). Such basic things are usually solved with a google search, like python image position, but there was no inchantation I could utter that would bring me the effect I wanted (oops. Bad example. I guess python image position would give a useful answer...) Another example, I found in pygame functions that would return something called an EventList. But whenever I searched for EventList to see what is that, I got back to the page with the functions that returned the EventList :-) Also, basic things like how does + operate on object xxx are impossible to google search. Anyway, thanks for the help. Alberto Monteiro -- http://mail.python.org/mailman/listinfo/python-list
Philippine Celebrities Sex Tips
you can find it here the Philippine Sexy Celebrities Sex Tips at http://www.pinoysexguru.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: number generator
On Sat, 2007-03-10 at 22:27 -0500, Terry Reedy wrote: Anton Vredegoor [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] | Terry Reedy wrote: | | Partitioning positive count m into n positive counts that sum to m is a | standard combinatorial problem at least 300 years old. The number of such | partitions, P(m,n) has no known exact formula [...] | [...] Steven pointed out that one can view the problem like this: | | 0001100010100 | | That would be [3,4,3,1,2] | | where the '1' elements are like dividing shutters that partition the row | of '0'. This means that the problem is reduced to permutations (albeit If any of the 1s appear at the ends or together, then you would have 0s in the partition, which is not allowed, as I understood the spec. Correct, the OP's spec doesn't allow 0s, but the problem can be easily transformed back and forth between positive partitions and non-negative partitions. In order to partition M into N positive numbers, partition (M-N) into N non-negative numbers and increase each part by 1. There must be some other constraint on what P(M,N) means, or I just solved a 300 year old problem. -Carsten -- http://mail.python.org/mailman/listinfo/python-list
Re: Formatted Input
Deep wrote: Hi all, I am a newbie to python I have an input of form one number space another number ie. 4 3 how can i assign these numbers to my variables?? Or with list comprehension: n1, n2 = [int(n) for n in raw_input().split()] Neither of these methods checks for errors (e.g. non-integers) -Larry -- http://mail.python.org/mailman/listinfo/python-list
Re: How to test if a key in a dictionary exists?
Frank wrote: Hi, does anyone know how one can test if, e.g., a dictionary 'name' has a key called 'name_key'? This would be possible: keys_of_names = names.keys() L = len(keys_of_names) for i in range(L): if keys_of_names[i] == name_key: print 'found' But certainly not efficient. I would expect there is something like: name.is_key(name_key) I appreciate your help! Frank Others have posted the direct answer but often you are wanting to do something with the key if it exists and the best method is: try: names['name_key']+=1 except KeyError: # # Key doesn't exist, create it, display error, or whatever you want # to do if it doesn't exist. # -Larry -- http://mail.python.org/mailman/listinfo/python-list
Re: PIL: reading bytes from Image
cyberco wrote: Thanks, I've tried the StringIO option as follows: = img = Image.open('/some/path/img.jpg') img.thumbnail((640,480)) file = StringIO, StringIO() img.save(file, 'JPEG') = But it gives me: = exceptions.TypeError Traceback (most recent call last) C:\Python24\lib\site-packages\PIL\Image.py in save(self, fp, format, **params) 1303 1304 try: - 1305 save_handler(self, fp, filename) 1306 finally: 1307 # do what we can to clean up C:\Python24\lib\site-packages\PIL\JpegImagePlugin.py in _save(im, fp, filename) 407 ) 408 -- 409 ImageFile._save(im, fp, [(jpeg, (0,0)+im.size, 0, rawmode)]) 410 411 def _save_cjpeg(im, fp, filename): C:\Python24\lib\site-packages\PIL\ImageFile.py in _save(im, fp, tile) 464 bufsize = max(MAXBLOCK, im.size[0] * 4) # see RawEncode.c 465 try: -- 466 fh = fp.fileno() 467 fp.flush() 468 except AttributeError: TypeError: descriptor 'fileno' of 'file' object needs an argument = It looks similar to the code in Sparklines except for the fact that the latter creates an Image from scratch. 2B Saving the image, in a format your client understands, to a file like object like StringIO.StringIO is an easy path to take. Sparklines shows this in action: http://bitworking.org/projects/sparklines/ max If it hasn't already bitten you it will: It is a BAD idea to use 'file' as a variable name. If you do, you mask the built-in file function. That is why most people use fp or something else. -Larry -- http://mail.python.org/mailman/listinfo/python-list
Re: New to Python
I do have previous experience with programming (much more than it's reasonable for one lifetime, BTW. I have the curse of never forgetting things I learn, so sometimes I catch myself thinking in archaic and extinct languages), but I found python particularly hard to learn (not as much as Haskell). Maybe I am not doing it the right way, trying to learn Python _and_ Python GUI interface at the same time. For example, yesterday I wanted to open a window, draw some image, and make it move. I tried it with tkinter and with pygame, but I didn't succeed - there was no way I could find how to begin the image in the center of the window (!!!). Such basic things are usually solved with a google search, like python image position, but there was no inchantation I could utter that would bring me the effect I wanted (oops. Bad example. I guess python image position would give a useful answer...) Another example, I found in pygame functions that would return something called an EventList. But whenever I searched for EventList to see what is that, I got back to the page with the functions that returned the EventList :-) Also, basic things like how does + operate on object xxx are impossible to google search. For which language they are? And in python you've got the interpreter loop, either explicitly by invoking python on the commandline and entering some statements, or implicitly by putting a import pdb; pdb.set_trace() call on a place where you are interested in toying around with objects. Then you start poking around, and find out that a Eventlist is nothing but a list - of events. I think you just have to adjust to the much more dynamic nature of python a bit. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: New to Python
Something like that? z = tuple(map(lambda x,y: x+y, x, y)) On 3/11/07, Alberto Vieira Ferreira Monteiro [EMAIL PROTECTED] wrote: Hi, I am new to Python, how stupid can be the questions I ask? For example, how can I add (mathematically) two tuples? x = (1,2) y = (3,4) How can I get z = (1 + 3, 2 + 4) ? Alberto Monteiro -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
backslashes in lists
Hi list, I'm trying to use a string with backslashes in a list. But Python parses strings in lists with repr(). alist = ['a', 'b', 'c:\some\path'] alist['a', 'b', 'c:\\some\\path'] print alist['a', 'b', 'c:\\some\\path'] I already tried str() and raw (r) but it didn't work. All I want is to keep a single backslash in the string since it is a path information. Can anyone help me, please? Thank you. _ O Windows Live Spaces está aqui! Descubra como é fácil criar seu espaço na Web e sua rede amigos. http://spaces.live.com/signup.aspx-- http://mail.python.org/mailman/listinfo/python-list
Re: backslashes in lists
The backslash is a key to enter especial characters, like breakline: '\n' There is two backslashes cause of this especial condition of this char, but if you try print the specific string you will see that only one backslash remain: print alist[2] On 3/12/07, Fabio Gomes [EMAIL PROTECTED] wrote: Hi list, I'm trying to use a string with backslashes in a list. But Python parses strings in lists with repr(). alist = ['a', 'b', 'c:\some\path'] alist ['a', 'b', 'c:\\some\\path'] print alist ['a', 'b', 'c:\\some\\path'] I already tried str() and raw (r) but it didn't work. All I want is to keep a single backslash in the string since it is a path information. Can anyone help me, please? Thank you. -- O Windows Live Spaces está aqui! Descubra como é fácil criar seu espaço na Web e sua rede amigos. Confira! http://spaces.live.com/signup.aspx -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
RE: backslashes in lists
Yes, Luca. I noticed that printing the list item will show the string as expected. But I need to print the entire list in the script I'm writing and doing that, the list will will be repr()'ed. Is there any way to print the entire list without being parsed by repr()? Date: Mon, 12 Mar 2007 12:00:19 -0300From: [EMAIL PROTECTED]: [EMAIL PROTECTED]: Re: backslashes in listsCC: [EMAIL PROTECTED] backslash is a key to enter especial characters, like breakline: '\n'There is two backslashes cause of this especial condition of this char, but if you try print the specific string you will see that only one backslash remain: print alist[2]On 3/12/07, Fabio Gomes [EMAIL PROTECTED] wrote: Hi list, I'm trying to use a string with backslashes in a list. But Python parses strings in lists with repr(). alist = ['a', 'b', 'c:\some\path'] alist ['a', 'b', 'c:\\some\\path'] print alist['a', 'b', 'c:\\some\\path'] I already tried str() and raw (r) but it didn't work. All I want is to keep a single backslash in the string since it is a path information. Can anyone help me, please? Thank you.O Windows Live Spaces está aqui! Descubra como é fácil criar seu espaço na Web e sua rede amigos. Confira! --http://mail.python.org/mailman/listinfo/python-list _ Busque em qualquer página da Web com alta proteção. Obtenha o Windows Live Toolbar GRATUITO ainda hoje! http://toolbar.live.com/-- http://mail.python.org/mailman/listinfo/python-list
Re: backslashes in lists
I don't know how ugly this look like, but { print str(alist).replace('', '\\') } works... On 3/12/07, Fabio Gomes [EMAIL PROTECTED] wrote: Yes, Luca. I noticed that printing the list item will show the string as expected. But I need to print the entire list in the script I'm writing and doing that, the list will will be repr()'ed. Is there any way to print the entire list without being parsed by repr()? -- Date: Mon, 12 Mar 2007 12:00:19 -0300 From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: Re: backslashes in lists CC: python-list@python.org The backslash is a key to enter especial characters, like breakline: '\n' There is two backslashes cause of this especial condition of this char, but if you try print the specific string you will see that only one backslash remain: print alist[2] On 3/12/07, *Fabio Gomes* [EMAIL PROTECTED] wrote: Hi list, I'm trying to use a string with backslashes in a list. But Python parses strings in lists with repr(). alist = ['a', 'b', 'c:\some\path'] alist ['a', 'b', 'c:\\some\\path'] print alist ['a', 'b', 'c:\\some\\path'] I already tried str() and raw (r) but it didn't work. All I want is to keep a single backslash in the string since it is a path information. Can anyone help me, please? Thank you. -- O Windows Live Spaces está aqui! Descubra como é fácil criar seu espaço na Web e sua rede amigos. Confira! http://spaces.live.com/signup.aspx -- http://mail.python.org/mailman/listinfo/python-list -- Busque em qualquer página da Web com alta proteção. Obtenha o Windows Live Toolbar GRATUITO ainda hoje! Experimente agora! http://toolbar.live.com/ -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
RE: backslashes in lists
On Mon, 2007-03-12 at 18:08 +0300, Fabio Gomes wrote: Yes, Luca. I noticed that printing the list item will show the string as expected. But I need to print the entire list in the script I'm writing and doing that, the list will will be repr()'ed. Is there any way to print the entire list without being parsed by repr()? It would be easier to help you if you told us what you are actually trying to achieve. What does printing the entire list give you that printing its individual items does not? -Carsten -- http://mail.python.org/mailman/listinfo/python-list
Re: Need help with a string plz! (newbie)
On 2007-03-12, Hendrik van Rooyen [EMAIL PROTECTED] wrote: Grant Edwards [EMAIL PROTECTED] wrote: Oh, thanks for the advice then. And as for Grant..look forward to seeing more of your posts. YOW! - some recognition at last! :) I see somebody pays attention to sigs -- which, BTW, are old quotes from the Zippy the Pinhead comic strip. www.zippythepinhead.com Thanks for that - I was wondering where you got hold of the skewed thinking which I enjoy reading so much. I grabbed the file full of quotes from the emacs distribution back around 1990, so that's why the pop-culture references are a bit dated. I don't know if emacs still includes Zippy quotes (of if they've been updated), but you used to be able to do esc-X yow and emacs would show you a random Zippy quote. -- Grant Edwards grante Yow! Jesus is my at POSTMASTER GENERAL... visi.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Python in a desktop environment
On 2007-03-11, David Cramer [EMAIL PROTECTED] wrote: On Mar 10, 10:52 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: David Cramer wrote: If you had an application that you were about to begin development on which you wanted to be cross platform (at least Mac and Windows), would you suggest using c++ and Python? I'd strongly consider a pure python solution (I'd choose wxpython), but if I needed to code backend stuff in a lower level language I'd use C rather than C++. Well we want it to be very robust, and python isn't exactly the fastest language, or one with the lowest overhead :) Python is _far_ more robust than C++. -- Grant Edwards grante Yow! If Robert Di Niro at assassinates Walter Slezak, visi.comwill Jodie Foster marry Bonzo?? -- http://mail.python.org/mailman/listinfo/python-list
RE: backslashes in lists
Nice, Lucas. But help me again, please. What about echoing the list: str(alist).replace('','\\')['a', 'b', 'c:\\some\\path'] Because in my script I'm echoing the list to mount lists into lists, like: list1 = ['name', 'test'] list2 = ['path', 'c:\some\path'] list = [list1, list2] print list[['name', 'test'], ['path', 'c:\\some\\path']] That's how it is coded in my script. What do you think. Is it possible to print list without the doubled backslash? Thank again, Lucas. Date: Mon, 12 Mar 2007 12:15:10 -0300From: [EMAIL PROTECTED]: [EMAIL PROTECTED]: Re: backslashes in listsCC: [EMAIL PROTECTED] don't know how ugly this look like, but { print str(alist).replace('', '\\') } works...On 3/12/07, Fabio Gomes [EMAIL PROTECTED] wrote: Yes, Luca. I noticed that printing the list item will show the string as expected. But I need to print the entire list in the script I'm writing and doing that, the list will will be repr()'ed. Is there any way to print the entire list without being parsed by repr()? Date: Mon, 12 Mar 2007 12:00:19 -0300From: [EMAIL PROTECTED]: [EMAIL PROTECTED]: Re: backslashes in listsCC: [EMAIL PROTECTED] backslash is a key to enter especial characters, like breakline: '\n'There is two backslashes cause of this especial condition of this char, but if you try print the specific string you will see that only one backslash remain: print alist[2]On 3/12/07, Fabio Gomes [EMAIL PROTECTED] wrote: Hi list, I'm trying to use a string with backslashes in a list. But Python parses strings in lists with repr(). alist = ['a', 'b', 'c:\some\path'] alist ['a', 'b', 'c:\\some\\path'] print alist['a', 'b', 'c:\\some\\path'] I already tried str() and raw (r) but it didn't work. All I want is to keep a single backslash in the string since it is a path information. Can anyone help me, please? Thank you.O Windows Live Spaces está aqui! Descubra como é fácil criar seu espaço na Web e sua rede amigos. Confira! --http://mail.python.org/mailman/listinfo/python-list Busque em qualquer página da Web com alta proteção. Obtenha o Windows Live Toolbar GRATUITO ainda hoje! Experimente agora! --http://mail.python.org/mailman/listinfo/python-list _ O Windows Live Spaces está aqui! Descubra como é fácil criar seu espaço na Web e sua rede amigos. http://spaces.live.com/signup.aspx-- http://mail.python.org/mailman/listinfo/python-list
nonlinear interpolation
I want to interpolate a data distribution with a function depending on various parameters; the function can be a Gaussian, a Breit-Wigner, a custom function. Where should I look? I am getting lost between matplotlib, numeric, numpy, scientific python, scipy, etc. etc. Any pointer would be well received :) Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list
Re: Python in a desktop environment
Grant Edwards a écrit : (snip) Python is _far_ more robust than C++. I wouldn't say so - robustness is a quality of a program, not of a language !-) -- http://mail.python.org/mailman/listinfo/python-list
nonlinear interpolation
I want to interpolate a data distribution with a function depending on various parameters; the function can be a Gaussian, a Breit-Wigner, a custom function. Where should I look? I am getting lost between matplotlib, numeric, numpy, scientific python, scipy, etc. etc. Any pointer would be well received :) Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list
Re: Python in a desktop environment
On 2007-03-12, Bruno Desthuilliers [EMAIL PROTECTED] wrote: Grant Edwards a écrit : (snip) Python is _far_ more robust than C++. I wouldn't say so - robustness is a quality of a program, not of a language !-) IMO, robustness is also a quality of a language. In language like C and C++, it's difficult to write a program that isn't full of potential crashes and exploits: buffer overflows, broken pointers, memory leaks, etc. Python eliminates many of those sources of problems, and is therefore a more robust language. -- Grant Edwards grante Yow! Uh-oh!! I forgot at to submit to COMPULSORY visi.comURINALYSIS! -- http://mail.python.org/mailman/listinfo/python-list
Newbie Question : grep
Hello, I am attempting to write my first Python script to extract some information from a file, and place it into another file. (I am trying to find the physical postions of 4 cells within an FPGA) I have a working solution, and would appreciate any comments. for line in lines: if placed in line: if i_a/i_b/ROM/ in line: pos = (line.split()[4]).split(_)[1] if B18 in line: print i_a/i_b/ROM/B18 [7:6] LOC =, pos elif B14 in line: print i_a/i_b/ROM/B14 [5:4] LOC =, pos elif B10 in line: print i_a/i_b/ROM/B10 [3:2] LOC =, pos elif B6 in line: print i_a/i_b/ROM/B6 [1:0] LOC =, pos else: print Error Specific questions - Use for Phrase in line or line.find(Phrase) = 0 ? - If I increase number of elements I am searching for, then I have more elif...elif. Is there a cleaner solution? Thanks for any feedback. Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: a better solution for GUI in python
On 3/11/07, Jarek Zgoda [EMAIL PROTECTED] wrote: Bjoern Schliessmann napisał(a): I'd recommend pyGTK. It's easy to use, delivers astonishing results and is perfectly portable as far as I know. And how does it look on Windows? :) On styled Windows XP it looks like any other styled application (counting those Qt and wx based). This is really an overstatement. While it uses the Windows theme manager to draw widgets, and will appear native in screenshots, nobody is going to mistake a Gtk app for a native Windows one in use. There are lots of behaviors and graphical differences from native applications. That said, in order to make a useful recommendation your requirements need to be better known. Browser based clients are often poor for high speed data entry, especially with highly trained data entry people. You simply don't have enough control over the browser environment, and you're limited in your ability to offload processing to the client. Ironing out browser differences is also no picnic. On the other hand you've got rapid and low cost deployment and updates. Licensing is the main reason I'd avoid pyQt, if the licensing fits your needs (or budget) then it's a perfectly reasonable solution. Gtk I consider an extremely poor contender as a cross platform toolkit. The runtime is enormous and it makes little effort to appear native on any non-GNOME platform. wxPython is also a perfectly reasonable solution, especially if you want a native seeming app on all platforms. If consistency of interface, rather than a native interface, is more important to you then Qt would probably be a better choice. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python in a desktop environment
Bruno Desthuilliers wrote: Grant Edwards a écrit : (snip) Python is _far_ more robust than C++. I wouldn't say so - robustness is a quality of a program, not of a language !-) Nope. Dealing with dangling references and double frees, complex copy-semantics that change only by a feeble character or via overloaded and thus hard to comprehend assignment operators are all properties of C++, and tremendously afflict robustness IMHO. Diez -- http://mail.python.org/mailman/listinfo/python-list
nonlinear interpolation
I want to interpolate a data distribution with a function depending on various parameters; the function can be a Gaussian, a Breit-Wigner, a custom function. Where should I look? I am getting lost between matplotlib, numeric, numpy, scientific python, scipy, etc. etc. Any pointer would be well received :) Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list
Readline()
I have been working on running an external process using subprocess.popen for a few days. The process is ran over the network to another machine. One thing I have found is that if I perform readline() on the stdout it will hang if the process loses connection. I have tried a few things in a test example: one is to use stdin.write then stdin.flush() which send a string that readline() will read and it ends correctly but doesn't work on the project I need it to work on. Another is to try using threads and ignoar the thread when the process has lost connection but this still leaves the open thread alive even when the main app has finished. I am relatively new to python and I may be making a fundemantal mistake in my implementation, can anyone please inform me of whether sticking with subprocess.popen and readline() is the correct procedure for this sort of task? And if anyone can point me in the correct implementation of this problem I would be gratefull. Thank you Stuart -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie Question : grep
[EMAIL PROTECTED] wrote: Hello, I am attempting to write my first Python script to extract some information from a file, and place it into another file. (I am trying to find the physical postions of 4 cells within an FPGA) I have a working solution, and would appreciate any comments. for line in lines: if placed in line: if i_a/i_b/ROM/ in line: pos = (line.split()[4]).split(_)[1] if B18 in line: print i_a/i_b/ROM/B18 [7:6] LOC =, pos elif B14 in line: print i_a/i_b/ROM/B14 [5:4] LOC =, pos elif B10 in line: print i_a/i_b/ROM/B10 [3:2] LOC =, pos elif B6 in line: print i_a/i_b/ROM/B6 [1:0] LOC =, pos else: print Error Specific questions - Use for Phrase in line or line.find(Phrase) = 0 ? - If I increase number of elements I am searching for, then I have more elif...elif. Is there a cleaner solution? Thanks for any feedback. Steven Something like (not tested): def search(search_gates, line): for gate, index in search_gates: pos = (line.split()[4]).split(_)[1] if gate in line: return i_a/i_b/ROM/%s %s LOC =%s % (gate, index, pos) return Error search_gates=[('B6', '[1:0]'), 'B10', '[3:2]'), 'B14', '[5:4]'), 'B17', '[7:6]')] for line in lines: print search(search_gates, line) -Larry -- http://mail.python.org/mailman/listinfo/python-list
Re: programmatically manipulation environment variables of the calling shell
Dennis Lee Bieber wrote: On Mon, 12 Mar 2007 12:33:58 +0200, Maxim Veksler [EMAIL PROTECTED] declaimed the following in comp.lang.python: Hello list, I'm trying to write a python script that would allow me to manipulate shell variables of the calling shell. I'm trying to write some logic that would know to add LD_LIBRARY_PATH to the users environment. In bash this is done with export, can I do this with python? (If at all possible because python is actually a sub process of bash). calling shell... Only OS I've encountered that allowed for a form of that was AmigaOS, which differentiated between shell specific (local) environment variables: set lev A Local Environment Variable and system-wide (global) ones: setenv gev Global Stuff The latter statement creates a file env:gev with Global Stuff as the contents (env: was a logical name for a system environment directory -- sys:env/ where sys: was a logical for the boot drive). As files, system environment variables could be manipulated by almost anything... Lacking memory protection, actually anything of anything could me manipulated... and it was a _great_ OS, really loved it! Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: nonlinear interpolation
Michele Simionato [EMAIL PROTECTED] writes: Any pointer would be well received :) Dunno about those libs but it helps to understand the mathematical options. Numerical Recipes by Teukolsky et al has understandable, cookbook-like advice about this stuff. I'm told that true numerics gurus scoff at it but it's at least a start. -- http://mail.python.org/mailman/listinfo/python-list
Re: nonlinear interpolation
On Mar 12, 5:28 pm, Paul Rubin http://[EMAIL PROTECTED] wrote: Michele Simionato [EMAIL PROTECTED] writes: Any pointer would be well received :) Dunno about those libs but it helps to understand the mathematical options. Numerical Recipes by Teukolsky et al has understandable, cookbook-like advice about this stuff. I'm told that true numerics gurus scoff at it but it's at least a start. No, I know about Numerical Recipes, I want an already-made solution. For instance I found one here http://dirac.cnrs-orleans.fr/ScientificPython/ScientificPythonManual/Scientific.Functions.LeastSquares-module.html but I wonder if I should use numpy or something else, since I am not following the progresses in numerical Python these days. P.S. sorry for the multiple post, google tricked me. -- http://mail.python.org/mailman/listinfo/python-list
Re: using python to visit web sites and print the web sites image to files
On Mar 12, 7:32 am, imx [EMAIL PROTECTED] wrote: I wonder whether python can be used to simulate a real user to do the following: 1) open a web site in a browser; 2) printscreen, so to copy the current active window image to clipboard; 3) save the image file to a real file Any pointer will be apprieciated! Xiong Google pywinauto. HTH Davy -- http://mail.python.org/mailman/listinfo/python-list
Re: backslashes in lists
just like the same way, but replace alist - list: str(list).replace('','\\') as the time you call str(object) you will have an object of type string, and you can do whatever you want/could do with it... what are you trying?! isn't more interesting use a hash table? On 3/12/07, Fabio Gomes [EMAIL PROTECTED] wrote: Nice, Lucas. But help me again, please. What about echoing the list: str(alist).replace('','\\') ['a', 'b', 'c:\\some\\path'] Because in my script I'm echoing the list to mount lists into lists, like: list1 = ['name', 'test'] list2 = ['path', 'c:\some\path'] list = [list1, list2] print list [['name', 'test'], ['path', 'c:\\some\\path']] That's how it is coded in my script. What do you think. Is it possible to print list without the doubled backslash? Thank again, Lucas. -- Date: Mon, 12 Mar 2007 12:15:10 -0300 From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: Re: backslashes in lists CC: python-list@python.org I don't know how ugly this look like, but { print str(alist).replace('', '\\') } works... On 3/12/07, * Fabio Gomes* [EMAIL PROTECTED] wrote: Yes, Luca. I noticed that printing the list item will show the string as expected. But I need to print the entire list in the script I'm writing and doing that, the list will will be repr()'ed. Is there any way to print the entire list without being parsed by repr()? -- Date: Mon, 12 Mar 2007 12:00:19 -0300 From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: Re: backslashes in lists CC: python-list@python.org The backslash is a key to enter especial characters, like breakline: '\n' There is two backslashes cause of this especial condition of this char, but if you try print the specific string you will see that only one backslash remain: print alist[2] On 3/12/07, *Fabio Gomes* [EMAIL PROTECTED] wrote: Hi list, I'm trying to use a string with backslashes in a list. But Python parses strings in lists with repr(). alist = ['a', 'b', 'c:\some\path'] alist ['a', 'b', 'c:\\some\\path'] print alist ['a', 'b', 'c:\\some\\path'] I already tried str() and raw (r) but it didn't work. All I want is to keep a single backslash in the string since it is a path information. Can anyone help me, please? Thank you. -- O Windows Live Spaces está aqui! Descubra como é fácil criar seu espaço na Web e sua rede amigos. Confira! http://spaces.live.com/signup.aspx -- http://mail.python.org/mailman/listinfo/python-list -- Busque em qualquer página da Web com alta proteção. Obtenha o Windows Live Toolbar GRATUITO ainda hoje! Experimente agora! http://toolbar.live.com/ -- http://mail.python.org/mailman/listinfo/python-list -- O Windows Live Spaces está aqui! Descubra como é fácil criar seu espaço na Web e sua rede amigos. Confira! http://spaces.live.com/signup.aspx -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: New to Python
In article [EMAIL PROTECTED], Dustan [EMAIL PROTECTED] wrote: What is the best way to get documentation about the functions and classes of python? I tried to google, but usually I can just find the __doc__ of the objects, without examples or anything that can help me use it. Alberto Monteiro Refer to this as a reference: http://docs.python.org/ It includes a tutorial and documentation on the functions and classes in all the global modules, as well as builtin functions (http:// docs.python.org/lib/built-in-funcs.html) and syntax. If you have prior experience with programming, you may be able to learn python from the tutorial, but otherwise, I would highly recommend you get a good book for beginners on python (http://wiki.python.org/moin/PythonBooks); there's plenty of them out there. Python in a Nutshell by Martelli (O'Reilly publ.) is very good. I also liked Learning Python by Lutz and Ascher (O'Reilly publ.) when I started Python, but I don't know if that's been updated recently. -- Lou Pecora (my views are my own) REMOVE THIS to email me. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python in a desktop environment
Diez B. Roggisch a écrit : Bruno Desthuilliers wrote: Grant Edwards a écrit : (snip) Python is _far_ more robust than C++. I wouldn't say so - robustness is a quality of a program, not of a language !-) Nope. Dealing with dangling references and double frees, complex copy-semantics that change only by a feeble character or via overloaded and thus hard to comprehend assignment operators are all properties of C++, Indeed and tremendously afflict robustness IMHO. robustness of programs written with this language, yes. NB : I'm afraid the smiley got lost somewhere between screen and readers, so here comes another one !-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie Question : grep
[EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] snip - If I increase number of elements I am searching for, then I have more elif...elif. Is there a cleaner solution? I'm not sure exactly what your lines look like, but this script implies that every line that matches 'i_a/i_b/ROM' is one of the known list you are looking for. Maybe that's exactly right... Below is some code that I think is an incremental improvement over writing lots of alternative if-statements. I beleive it has the same behaviour, though it is totally untested: tags = [ ['B18', (7, 6)], ['B14', (5, 4)], ['B10', (3, 2)], ['B6', (1, 0)], ] for line in lines: if placed in line: if i_a/i_b/ROM/ in line: pos = (line.split()[4]).split(_)[1] found = False for (tag, (start, end)) in tags: if tag in line: found = True print i_a/i_b/ROM/%s [%i:%i] LOC = %\ (pos, tag, start, end) break This way, you just need to maintain your data structure (tags), instead of writing lots of repettitive code. If there is a definite pattern to the part that looks like a slice (what I am calling (start, end)), then you could programmatically generate that as well, of course. The list of things you are looking for could be in a separate file, etc. The sensible thing to do sort of depends on how big this list of stuff you are looking for is going to grow and how much you are going to use this program. Do what makes sense for you. You may want to explore the 're' module as well (regular expressions) http://docs.python.org/modindex.html , which may or may not improve performance, readability, maintainability, etc. See also section 10.10 of the Python Tutorial if you are interested in code performance issues: http://docs.python.org/tut/tut.html Hope that helps, -ej -- http://mail.python.org/mailman/listinfo/python-list
RE: backslashes in lists
It didn't work. I decided to submit the code in the list.It is a script running with Jython to modify some configurations in the Websphere Application Server that has a Java like command line that interprets jython or jacl. I decided to use Jython.All the properties in that server are stored in hierarchy in the form of lists into lists. An exemple of one of the properties follows:['systemProperties', [[['description', 'Arquivo de configuracao da arquitetura'], ['name', 'A_INI'], ['required', 'false'], ['value', '/xml/a_ini.xml']], [['description', 'Raiz do Ambiente'], ['name', 'A_ROOT'], ['required', 'false'], ['value', 'file://D:\\A\\D9'All above in a single string.To make the things easier to me and the other people who will read that script, I decided to declare each subset of lists separatly. Something like that:list1 = ['name', 'value']list2 = ['path', 'c:\some\path']list3 = [list1, list2]But doing that, list2 will be parsed by repr() and will receive an extra '\' when inserted int list3, messing up with the path information. I need some aproach to build that string without have to write it in one long and confuse string. Maybe hash tables will be the answer. I need to read about it.The entire code follows, remembering you that AdminConfig is an object present only in the WebSphere:## Creates the JVM custom properties A_INI and A_ROOT## Custom Propertiesattr1_desc = ['description', 'Arquivo de configuracao da arquitetura']attr1_name = ['name', 'A_INI']attr1_required = ['required', 'false']attr1_value= ['value', '/xml/a_ini.xml']attr1_List = [attr1_desc, attr1_name, attr1_required, attr1_value]attr2_desc = ['description', 'Raiz do Ambiente']attr2_name = ['name', 'A_ROOT']attr2_required = ['required', 'false']# ID of all application serversallServers = AdminConfig.getid('/Server:/')import javalineSeparator = java.lang.System.getProperty('line.separator')arrayAllServers = allServers.split(lineSeparator)# processing for each serverfor serverID in arrayAllServers: # bypass if it isn't an (real) application server if AdminConfig.showAttribute(serverID, 'name') == 'dmgr':continue if AdminConfig.showAttribute(serverID, 'name') == 'nodeagent':continue if AdminConfig.showAttribute(serverID, 'name') == 'webserver':continue serverName = AdminConfig.showAttribute(serverID, 'name') print 'Atualizando o servidor', serverName, '...' jvm = AdminConfig.list('JavaVirtualMachine', serverID) path = 'file://D:\\A\\' + serverName[5:] attr2_value = ['value', path] attr2_List = [attr2_desc, attr2_name, attr2_required, attr2_value] attr_List = [attr1_List, attr2_List] property= ['systemProperties', attr_List] AdminConfig.modify(jvm, [property])print 'Salvando configuracoes...'AdminConfig.save()#EOF Date: Mon, 12 Mar 2007 13:40:58 -0300From: [EMAIL PROTECTED]: [EMAIL PROTECTED]: Re: backslashes in listsCC: [EMAIL PROTECTED] like the same way, but replace alist - list:str(list).replace('','\\')as the time you call str(object) you will have an object of type string, and you can do whatever you want/could do with it... what are you trying?! isn't more interesting use a hash table?On 3/12/07, Fabio Gomes [EMAIL PROTECTED] wrote: Nice, Lucas. But help me again, please. What about echoing the list: str(alist).replace('','\\')['a', 'b', 'c:\\some\\path'] Because in my script I'm echoing the list to mount lists into lists, like: list1 = ['name', 'test'] list2 = ['path', 'c:\some\path'] list = [list1, list2] print list[['name', 'test'], ['path', 'c:\\some\\path']] That's how it is coded in my script. What do you think. Is it possible to print list without the doubled backslash? Thank again, Lucas. Date: Mon, 12 Mar 2007 12:15:10 -0300 From: [EMAIL PROTECTED]: [EMAIL PROTECTED]: Re: backslashes in listsCC: python-list@python.org I don't know how ugly this look like, but { print str(alist).replace('', '\\') } works...On 3/12/07, Fabio Gomes [EMAIL PROTECTED] wrote: Yes, Luca. I noticed that printing the list item will show the string as expected. But I need to print the entire list in the script I'm writing and doing that, the list will will be repr()'ed. Is there any way to print the entire list without being parsed by repr()? Date: Mon, 12 Mar 2007 12:00:19 -0300From: [EMAIL PROTECTED]: [EMAIL PROTECTED]: Re: backslashes in listsCC: [EMAIL PROTECTED] backslash is a key to enter especial characters, like breakline: '\n'There is two backslashes cause of this especial condition of this char, but if you try print the specific string you will see that only one backslash remain: print alist[2]On 3/12/07, Fabio Gomes [EMAIL PROTECTED] wrote: Hi list, I'm trying to use a string with backslashes in a list. But Python parses strings in lists with repr(). alist = ['a', 'b', 'c:\some\path'] alist ['a', 'b', 'c:\\some\\path'] print alist['a', 'b', 'c:\\some\\path'] I already tried
Re: Newbie Question : grep
Sorry, I forgot to paste the modified version of my code in the post:. I think this is the same behaviour: for line in lines: if placed in line: if i_a/i_b/ROM/ in line: pos = (line.split()[4]).split(_)[1] found = False for (tag, (start, end)) in tags: if tag in line: found = True print i_a/i_b/ROM/%s [%i:%i] LOC = %\ (pos, tag, start, end) break if not found: print Error -- http://mail.python.org/mailman/listinfo/python-list
Re: New to Python
Diez B. Roggisch wrote: Also, basic things like how does + operate on object xxx are impossible to google search. For which language they are? None :-) And in python you've got the interpreter loop, either explicitly by invoking python on the commandline and entering some statements, or implicitly by putting a import pdb; pdb.set_trace() call on a place where you are interested in toying around with objects. Ah! This is a precious help. This should be in the tutorials!!! I think you just have to adjust to the much more dynamic nature of python a bit. I know. Maybe I am trying to adjust to too many things at the same time. Alberto Monteiro -- http://mail.python.org/mailman/listinfo/python-list
Re: using python to visit web sites and print the web sites image to files
I wonder whether python can be used to simulate a real user to do the following: 1) open a web site in a browser; 2) printscreen, so to copy the current active window image to clipboard; 3) save the image file to a real file Any pointer will be apprieciated! Which OS? -- http://mail.python.org/mailman/listinfo/python-list
Re: nonlinear interpolation
Michele Simionato wrote: On Mar 12, 5:28 pm, Paul Rubin http://[EMAIL PROTECTED] wrote: Michele Simionato [EMAIL PROTECTED] writes: Any pointer would be well received :) Dunno about those libs but it helps to understand the mathematical options. Numerical Recipes by Teukolsky et al has understandable, cookbook-like advice about this stuff. I'm told that true numerics gurus scoff at it but it's at least a start. No, I know about Numerical Recipes, I want an already-made solution. For instance I found one here http://dirac.cnrs-orleans.fr/ScientificPython/ScientificPythonManual/Scientific.Functions.LeastSquares-module.html but I wonder if I should use numpy or something else, since I am not following the progresses in numerical Python these days. It sounds like you want nonlinear curve fitting rather than interpolation. I do recommend using numpy as the underlying array package, but it does not provide any curve fitting itself. The 2.7 branch of ScientificPython can work with numpy instead of Numeric, if you like. See the README. http://sourcesup.cru.fr/projects/scientific-py/ scipy also has a variety of curve fitting routines at the expense of a more involved install. scipy.optimize.leastsq() might be sufficient for you, but the scipy.odr package is much more flexible (but get scipy from SVN for that; the latest release has some unfortunate bugs in that package). -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: backslashes in lists
hehe, só vendo o ['Arquivo de configuracao da arquitetura'] da pra ver que é brasileiro =) I didn't undestand, what didn't worked? I've tryied this, and all went ok: list1 = ['name', 'value'] list2 = ['path', 'c:\some\path'] list3 = [list1, list2] print str(list3).replace('','\\') [['name', 'value'], ['path', 'c:\some\path']] On 3/12/07, Fabio Gomes [EMAIL PROTECTED] wrote: It didn't work. I decided to submit the code in the list. It is a script running with Jython to modify some configurations in the Websphere Application Server that has a Java like command line that interprets jython or jacl. I decided to use Jython. All the properties in that server are stored in hierarchy in the form of lists into lists. An exemple of one of the properties follows: ['systemProperties', [[['description', 'Arquivo de configuracao da arquitetura'], ['name', 'A_INI'], ['required', 'false'], ['value', '/xml/a_ini.xml']], [['description', 'Raiz do Ambiente'], ['name', 'A_ROOT'], ['required', 'false'], ['value', 'file://D:\\A\\D9' All above in a single string. To make the things easier to me and the other people who will read that script, I decided to declare each subset of lists separatly. Something like that: list1 = ['name', 'value'] list2 = ['path', 'c:\some\path'] list3 = [list1, list2] But doing that, list2 will be parsed by repr() and will receive an extra '\' when inserted int list3, messing up with the path information. I need some aproach to build that string without have to write it in one long and confuse string. Maybe hash tables will be the answer. I need to read about it. The entire code follows, remembering you that AdminConfig is an object present only in the WebSphere: # # Creates the JVM custom properties A_INI and A_ROOT # # Custom Properties attr1_desc = ['description', 'Arquivo de configuracao da arquitetura'] attr1_name = ['name', 'A_INI'] attr1_required = ['required', 'false'] attr1_value= ['value', '/xml/a_ini.xml'] attr1_List = [attr1_desc, attr1_name, attr1_required, attr1_value] attr2_desc = ['description', 'Raiz do Ambiente'] attr2_name = ['name', 'A_ROOT'] attr2_required = ['required', 'false'] # ID of all application servers allServers = AdminConfig.getid('/Server:/') import java lineSeparator = java.lang.System.getProperty('line.separator') arrayAllServers = allServers.split(lineSeparator) # processing for each server for serverID in arrayAllServers: # bypass if it isn't an (real) application server if AdminConfig.showAttribute(serverID, 'name') == 'dmgr': continue if AdminConfig.showAttribute(serverID, 'name') == 'nodeagent': continue if AdminConfig.showAttribute(serverID, 'name') == 'webserver': continue serverName = AdminConfig.showAttribute(serverID, 'name') print 'Atualizando o servidor', serverName, '...' jvm = AdminConfig.list('JavaVirtualMachine', serverID) path = 'file://D:\\A\\' + serverName[5:] attr2_value = ['value', path] attr2_List = [attr2_desc, attr2_name, attr2_required, attr2_value] attr_List = [attr1_List, attr2_List] property= ['systemProperties', attr_List] AdminConfig.modify(jvm, [property]) print 'Salvando configuracoes...' AdminConfig.save() #EOF -- Date: Mon, 12 Mar 2007 13:40:58 -0300 From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: Re: backslashes in lists CC: python-list@python.org just like the same way, but replace alist - list: str(list).replace('','\\') as the time you call str(object) you will have an object of type string, and you can do whatever you want/could do with it... what are you trying?! isn't more interesting use a hash table? On 3/12/07, *Fabio Gomes* [EMAIL PROTECTED] wrote: Nice, Lucas. But help me again, please. What about echoing the list: str(alist).replace('','\\') ['a', 'b', 'c:\\some\\path'] Because in my script I'm echoing the list to mount lists into lists, like: list1 = ['name', 'test'] list2 = ['path', 'c:\some\path'] list = [list1, list2] print list [['name', 'test'], ['path', 'c:\\some\\path']] That's how it is coded in my script. What do you think. Is it possible to print list without the doubled backslash? Thank again, Lucas. -- Date: Mon, 12 Mar 2007 12:15:10 -0300 From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: Re: backslashes in lists CC: python-list@python.org I don't know how ugly this look like, but { print str(alist).replace('', '\\') } works... On 3/12/07, * Fabio Gomes* [EMAIL PROTECTED] wrote: Yes, Luca. I noticed that printing the list item will show the string as expected. But I need to print the entire list in the script I'm writing and doing that, the list will will be repr()'ed. Is there any way to print the entire list without being parsed by repr()? -- Date: Mon, 12 Mar 2007 12:00:19 -0300 From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: Re:
Re: Watching a file another app is writing
Nick Vatamaniuc wrote: On Mar 11, 3:36 pm, Gordon Airporte [EMAIL PROTECTED] wrote: I'm trying to find a way to take a file that another program has opened and writes to periodically, open it simultaneously in Python, and automatically update some of my objects in Python when the file is written to. I can open the file and manually readlines() from it to keep up to date, it's the automatic part I'm having trouble with. This is on Windows. You might need to look at pywin32 for Windows specific ways to listen to file changed event. On Unix a quick shortcut would be to simply read the output of 'tail - f file' command... tail -f just checks the file size once a second. It's not doing anything exciting. Windows, of course, actually has a mechanism for finding out that files have changed, so that will work. Note that if you're doing this as a means of interprocess communication, there are better ways. John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie Question : grep
On Mar 12, 10:01 am, Erik Johnson [EMAIL PROTECTED] wrote: Sorry, I forgot to paste the modified version of my code in the post:. I think this is the same behaviour: for line in lines: if placed in line: if i_a/i_b/ROM/ in line: pos = (line.split()[4]).split(_)[1] found = False for (tag, (start, end)) in tags: if tag in line: found = True print i_a/i_b/ROM/%s [%i:%i] LOC = %\ (pos, tag, start, end) break if not found: print Error Instead of using a sentinal value (i.e., found), one can use the 'else' clause of a 'for' loop... pos = (line.split()[4]).split(_)[1] for (tag, (start,end)) in tags: if tag in line: print i_a/i_b/ROM/%s [%i:%i] LOC=%s %\ (pos,tag,start,end) break else print Error -- Hope this helps, Steven -- http://mail.python.org/mailman/listinfo/python-list
glob.glob output
import string import os f = open (c:\\servername.txt, 'r') linelist = f.read() lineLog = string.split(linelist, '\n') lineLog = lineLog [:-1] #print lineLog for l in lineLog: path1 = + l + \\server*\\*\\xtRec* glob.glob(path1) When I run above from command line python, It prints the output of glob.glob but when I run it as a script, it does not print anything I know that there are files like xtRec* inside those folders.. and glob.glob does spits the path if run from python command line. I tried something like this but did not work: for l in lineLog: path1 = + l + \\server*\\*\\xtRec* xtRec = glob.glob(path1) print xtRec No results... xtRec = [] for l in lineLog: path1 = + l + \\server*\\*\\xtRec* xtrec = glob.glob(path1) print xtRec No luck here either. Seems like I am doing here something reallt silly mistake.. Thank you, hj -- http://mail.python.org/mailman/listinfo/python-list
File locking
I'm always disappointed when I find something that Python doesn't handle in a platform independent way. It seems to me that file locking is in that boat. 1. I don't see a way to atomically open a file for writing if and only if it doesn't exist without resorting to os.open and specialized platform O_XXX flags. 2. I don't see a way to atomically open a file for writing and obtain a lock on the file. 3. I don't see a platform independent way to obtain a lock on a file. You have to do something goofy like if sys.platform == win32: import msvcrt else: import fcntl and then similar things to call the correct functions with the correct flags. Please let me know if I'm missing something since they seem like normal file operations that I would hope Python would abstract away. If not, are there any PEPs concerning this for Python3K? Thanks, Jeff -- http://mail.python.org/mailman/listinfo/python-list
Re: glob.glob output
On Mar 12, 1:58 pm, Hitesh [EMAIL PROTECTED] wrote: import string import os f = open (c:\\servername.txt, 'r') linelist = f.read() lineLog = string.split(linelist, '\n') lineLog = lineLog [:-1] #print lineLog for l in lineLog: path1 = + l + \\server*\\*\\xtRec* glob.glob(path1) When I run above from command line python, It prints the output of glob.glob but when I run it as a script, it does not print anything I know that there are files like xtRec* inside those folders.. and glob.glob does spits the path if run from python command line. I tried something like this but did not work: for l in lineLog: path1 = + l + \\server*\\*\\xtRec* xtRec = glob.glob(path1) print xtRec No results... xtRec = [] for l in lineLog: path1 = + l + \\server*\\*\\xtRec* xtrec = glob.glob(path1) print xtRec No luck here either. Seems like I am doing here something reallt silly mistake.. Thank you, hj I am using pythonWin and command line means Interactive Shell. -- http://mail.python.org/mailman/listinfo/python-list
Re: Watching a file another app is writing
Gordon Airporte wrote: I'm trying to find a way to take a file that another program has opened and writes to periodically, open it simultaneously in Python, and automatically update some of my objects in Python when the file is written to. I can open the file and manually readlines() from it to keep up to date, it's the automatic part I'm having trouble with. This is on Windows. It occurs to me under Unix you could perhaps get your first program to write to a named pipe, which you 2nd program could read from. See http://en.wikipedia.org/wiki/Named_pipe Jeremy -- Jeremy Sanders http://www.jeremysanders.net/ -- http://mail.python.org/mailman/listinfo/python-list
RE: Watching a file another app is writing
What kind of file is it? CSV? -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jeremy Sanders Sent: Monday, March 12, 2007 11:26 AM To: python-list@python.org Subject: Re: Watching a file another app is writing Gordon Airporte wrote: I'm trying to find a way to take a file that another program has opened and writes to periodically, open it simultaneously in Python, and automatically update some of my objects in Python when the file is written to. I can open the file and manually readlines() from it to keep up to date, it's the automatic part I'm having trouble with. This is on Windows. It occurs to me under Unix you could perhaps get your first program to write to a named pipe, which you 2nd program could read from. See http://en.wikipedia.org/wiki/Named_pipe Jeremy -- Jeremy Sanders http://www.jeremysanders.net/ -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie Question : grep
On 12 Mar, 18:55, [EMAIL PROTECTED] wrote: On Mar 12, 10:01 am, Erik Johnson [EMAIL PROTECTED] wrote: Sorry, I forgot to paste the modified version of my code in the post:. I think this is the same behaviour: for line in lines: if placed in line: if i_a/i_b/ROM/ in line: pos = (line.split()[4]).split(_)[1] found = False for (tag, (start, end)) in tags: if tag in line: found = True print i_a/i_b/ROM/%s [%i:%i] LOC = %\ (pos, tag, start, end) break if not found: print Error Instead of using a sentinal value (i.e., found), one can use the 'else' clause of a 'for' loop... pos = (line.split()[4]).split(_)[1] for (tag, (start,end)) in tags: if tag in line: print i_a/i_b/ROM/%s [%i:%i] LOC=%s %\ (pos,tag,start,end) break else print Error -- Hope this helps, Steven Thanks for the responses. I had an inkling what the solution may be, but I wondering whether I could avoid the nested loops (i.e. loop every line and then loop every pattern), maybe using maps or list comprehensions (this is just intellectual curiosity as the current solution obviously does the job. Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: glob.glob output
On Mar 12, 2:12 pm, Hitesh [EMAIL PROTECTED] wrote: On Mar 12, 1:58 pm, Hitesh [EMAIL PROTECTED] wrote: import string import os f = open (c:\\servername.txt, 'r') linelist = f.read() lineLog = string.split(linelist, '\n') lineLog = lineLog [:-1] #print lineLog for l in lineLog: path1 = + l + \\server*\\*\\xtRec* glob.glob(path1) When I run above from command line python, It prints the output of glob.glob but when I run it as a script, it does not print anything I know that there are files like xtRec* inside those folders.. and glob.glob does spits the path if run from python command line. I tried something like this but did not work: for l in lineLog: path1 = + l + \\server*\\*\\xtRec* xtRec = glob.glob(path1) print xtRec No results... xtRec = [] for l in lineLog: path1 = + l + \\server*\\*\\xtRec* xtrec = glob.glob(path1) print xtRec No luck here either. Seems like I am doing here something reallt silly mistake.. Thank you, hj I am using pythonWin and command line means Interactive Shell.- Hide quoted text - - Show quoted text - all right seems like I got it.. it's the looping part. I need to append the list. hj -- http://mail.python.org/mailman/listinfo/python-list
Re: File locking
In [EMAIL PROTECTED], Dr. Who wrote: Please let me know if I'm missing something since they seem like normal file operations that I would hope Python would abstract away. I don't think of them as normal operations. They are extra stuff that is not only dependent on the operating system but also on the file system in use. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: Watching a file another app is writing
In article [EMAIL PROTECTED], John Nagle wrote: On Unix a quick shortcut would be to simply read the output of 'tail - f file' command... tail -f just checks the file size once a second. It's not doing anything exciting. That's not actually always true these days. *BSD, at least, use 'kqueue' to avoid busy-wait on tail -f. -- http://mail.python.org/mailman/listinfo/python-list
Pydev 1.3.0 Released
Hi All, Pydev and Pydev Extensions 1.3.0 have been released Details on Pydev Extensions: http://www.fabioz.com/pydev Details on Pydev: http://pydev.sf.net Details on its development: http://pydev.blogspot.com Release Highlights in Pydev Extensions: - * Find References: Ctrl+Shift+G can be used to find the references to the selected token in the editor * Fix: Code-analysis: Fixed false positive for statement with no effect Release Highlights in Pydev: -- * Code-completion: Deep analysis for discovering arguments in constructs 'from imports' now can be configured given the number of chars of the qualifier * Refactoring for override methods: changed so that it uses the pydev code-completion engine for getting the hierarchy and methods * Fix: Python Nature Restore: begin rule does not match outer scope rule fixed * Fix: Package Explorer: if show-in is in a deep structure, it will show it is the 1st try and not only in the 2nd * Fix: Package Explorer: some intercepts removed elements incorrectly, and ended up messing the navigator and search (which has 'null' elements because of that) What is PyDev? --- PyDev is a plugin that enables users to use Eclipse for Python and Jython development -- making Eclipse a first class Python IDE -- It comes with many goodies such as code completion, syntax highlighting, syntax analysis, refactor, debug and many others. Cheers, -- Fabio Zadrozny -- Software Developer ESSS - Engineering Simulation and Scientific Software http://www.esss.com.br Pydev Extensions http://www.fabioz.com/pydev Pydev - Python Development Enviroment for Eclipse http://pydev.sf.net http://pydev.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Watching a file another app is writing
Gabriel Genellina wrote: This article explains it in detail: http://tgolden.sc.sabren.com/python/win32_how_do_i/watch_directory_for_changes.html BTW, it's the top result on Google for python notify file change windows --Gabriel Genellina Ah, excelent. Thank you. I'd started with the pywin32 documentation, where I did manage to find FindFirstChangeNotification(). I had to go to bed before I could get to Google to figure out how to use it. Having just tested it, it seems that my problem is now caching. These only trigger when the file is written to disk, and for the small amounts of data I'm dealing with that's not with every transaction. This is probably why tail wasn't working for me either, with the added complication of it locking the file. -- http://mail.python.org/mailman/listinfo/python-list
Re: Single string print statements on multiple lines.
http://www.catb.org/~esr/faqs/smart-questions.html Don't post homework questions. -- http://mail.python.org/mailman/listinfo/python-list
Re: New to Python
I read http://diveintopython.org/ online, and covered a lot of Python territory nicely with this. Greg -- http://mail.python.org/mailman/listinfo/python-list
Re: Watching a file another app is writing
Vishal Bhargava wrote: What kind of file is it? CSV? It's a hand history file generated by an online poker client, thus it probably keeps it's data pretty much to itself otherwise, and in any case I'm not a Windows programmer so I probably don't have the stomach to get very deep into its process communication mechanisms. It occurs to me under Unix you could perhaps get your first program to write to a named pipe, which you 2nd program could read from. See http://en.wikipedia.org/wiki/Named_pipe -- http://mail.python.org/mailman/listinfo/python-list
Re: using python to visit web sites and print the web sites image to files
You can definitely create a web bot with python. It doesn't require that you drive A real web browser. There are libraries to open web pages, scrape their contents, and do downloading. That would make your bot platform neutral. Driving a GUI browser has the risk of being a brittle script that might not handle different browsers, different platforms, maybe even not handle different versions. I run a mediawiki web site, and found a handy python-based library written to manage it called pywikipediabot at http://sourceforge.net/projects/pywikipediabot/. Okay, this library won't do your leg work for you, but it has pieces and parts that demonstrate how to use python to surf a web site. Then, with an HTML parser, you can hunt down images. Greg -- http://mail.python.org/mailman/listinfo/python-list
Re: How to test if a key in a dictionary exists?
On Mar 11, 11:49 pm, John Machin [EMAIL PROTECTED] wrote: On Mar 12, 3:19 pm, [EMAIL PROTECTED] (Alex Martelli) wrote: Paul McGuire [EMAIL PROTECTED] wrote: will be. For instance, when working with data from 0 to 100 and looking for frequencies by decade, you can initialize the histogram- dict with: for i in range(10): histodict[i] = 0 A better way, of course (also saving the histodict = {} which you didn't mention but surely intended) would be: histodict = dict.fromkeys(range(10), 0) In Python, in general, the more conceptually compact, direct, simple and higher-abstraction approach tends to be faster as well, BTW. That's so true, especially if it's matched to the problem space, isn't too new, and doesn't need looking up in the docs :-) Python 2.1.3 (#35, Apr 8 2002, 17:47:50) [MSC 32 bit (Intel)] on win32 Type copyright, credits or license for more information. histodict = dict.fromkeys(range(10), 0) Traceback (most recent call last): File stdin, line 1, in ? NameError: name 'dict' is not defined histolist = [0] * 10 histolist[3] += 1 histolist [0, 0, 0, 1, 0, 0, 0, 0, 0, 0] In defense of my original if:else: idiom, I'll point out that there may be more to be done when the key is absent than simply creating a new one and initializing it. Also, a dictionary doesn't need an integer index, so I can create bins such as '2.01','2.02',etc. And in some cases, it's not known what the range of the keys will be making it difficult to pre-allocate the list. And yes, the empty buckets will need to be created for graphing purposes, but that can be done after the test has completed so that the only empty buckets that need be created are those between the outliers. Cheers, John -- http://mail.python.org/mailman/listinfo/python-list
Re: using python to visit web sites and print the web sites image to files
Goldfish wrote: I run a mediawiki web site, and found a handy python-based library written to manage it called pywikipediabot at http://sourceforge.net/projects/pywikipediabot/. This sounds interesting. My daughter had a nightmare that a hacker invaded her Orkut and blanked all 1500+ scraps. This is not impossible. Maybe I should save the contents to a file... Alberto Monteiro -- http://mail.python.org/mailman/listinfo/python-list
Re: glob.glob output
Hitesh a écrit : import string import os f = open (c:\\servername.txt, 'r') linelist = f.read() lineLog = string.split(linelist, '\n') lineLog = lineLog [:-1] #print lineLog for l in lineLog: path1 = + l + \\server*\\*\\xtRec* glob.glob(path1) And ? What are you doing then with return value of glob.glob ? BTW, seems like an arbitrarily overcomplicated way to do: from glob import glob source = open(rc:\\servername.txt, 'r') try: for line in source: if line.strip(): found = glob(r\\%s\server*\*\xtRec* % line) print \n.join(found) finally: source.close() When I run above from command line python, It prints the output of glob.glob but when I run it as a script, it does not print anything Not without an explicit print statement. This behaviour is useful in the interactive python shell, but would be really annoying in normal use. I know that there are files like xtRec* inside those folders.. and glob.glob does spits the path if run from python command line. I tried something like this but did not work: for l in lineLog: path1 = + l + \\server*\\*\\xtRec* xtRec = glob.glob(path1) print xtRec No results... With the same source file, on the same filesystem ? Unless your xtRec* files have been deleted between both tests you should have something here. xtRec = [] for l in lineLog: path1 = + l + \\server*\\*\\xtRec* xtrec = glob.glob(path1) You're rebinding xtRec each turn. This is probably not what you want. -- http://mail.python.org/mailman/listinfo/python-list
Find the path of a running .py program
Hi All! There was a thread here, more than a month ago. It was about finding the path of a .py file. I suggested os.abspath(__file__). Others told that sys.argv[0] is better. I was not sure why I did not like that solution. Now I ran into the problem again, and I now I remember what is the problem with that. For windows service applications, it does not work. The running program will be pythonservice.exe. Usually we want to know where the python program (.py sources) are. So, if you ever write a windows service in Python, make sure that you os.chdir to the correct directory before you do anything else. Original thread: http://groups.google.com/group/comp.lang.python/browse_thread/thread/d1a674a2d42741ee/9763b5a8ab48b0a0?lnk=stq=python+__file__+gandalf+argvrnum=2hl=hu#9763b5a8ab48b0a0 Here is a snippet that helped me to overcome the problem: import sys,os os.chdir(os.path.split(__file__)[0]) keywords: windows, service, startup directory, startup folder, path of a .py program I hope this comment will help others in the future. Cheers, Laszlo -- http://mail.python.org/mailman/listinfo/python-list
Re: threading and iterator crashing interpreter
On Mar 11, 8:35 am, Janto Dreijer [EMAIL PROTECTED] wrote: On Mar 11, 3:27 pm, Gabriel Genellina [EMAIL PROTECTED] wrote: At least, the problem of using the same generator from different threads still remains, if you don't use my modified code. In general, when using multiple threads you always need some way to syncronize access to shared objects. You are lucky with Sessions because append is an atomic operation on lists; for more information see http://effbot.org/pyfaq/what-kinds-of-global-value-mutation-are-threa... Again you're right. But even putting a try-except:return around the random.choice still manages to break the interpreter. I'm not looking for any meaningful output really. I just want it not to break. I think you need to clarify what you mean by break. Python tries to prevent C-level corruption (segfaults, etc), but does NOT attempt to prevent python-level corruption. The python-level corruption will *probably* be localized (and the objects involved could be deleted, no harm done), but there's no guarantee that they won't involve some global too. But the examples you give involve C-level corruption. They're not using some low-level interface either, so they're genuine bugs. login1 did segfault for me, but the output is random and usually very long. login2 is somewhat random as well, but much shorter and to the point: Exception exceptions.SystemError: '../Python/traceback.c:96: bad argument to internal function' in generator object at 0xa7956aec ignored Exception exceptions.SystemError: '../Python/traceback.c:96: bad argument to internal function' in generator object at 0xa79569ac ignored Exception exceptions.SystemError: '../Python/traceback.c:96: bad argument to internal function' in generator object at 0xa795656c ignored Exception exceptions.SystemError: '../Python/traceback.c:96: bad argument to internal function' in generator object at 0xa795ebec ignored Segmentation fault Blah! I was trying to trace it down, but then the phase of the moon changed and login2 (as well as my variations therein) stopped failing. login1 still segfaults though. And login1 does sometimes give me that weird restricted mode error, so you're not alone. I do remember reading something about generators having a pointer to the thread they're created in, and having problems when migrated between threads. I don't have time to find the posts or bug reports right now, but at least that gives you something to look for (before filing a bug report). Actually, I have a few more minutes. http://mail.python.org/pipermail/python-dev/2006-October/069470.html http://sourceforge.net/tracker/index.php?func=detailaid=1579370group_id=5470atid=105470 That refers to a generator crash. You are using generators, but also getting a weird dict error. Maybe related, maybe not. I'll figure out if I've got a fixed version or not when I get back. -- http://mail.python.org/mailman/listinfo/python-list