Re: Interpreting Left to right?
On 6/24/2011 12:32 AM, Chetan Harjani wrote: x=y=some string And we know that python interprets from left to right. Read the doc. 5.14. Evaluation order Python evaluates expressions from left to right. Notice that while evaluating an assignment, the right-hand side is evaluated before the left-hand side. another example: (1,2) + 3, here, python raises a TypeError can only concatenate tuple(not int) to tuple but we know (3,) is a tuple as seen by following: But (3,) is not what you wrote;-). The comma operator has the lowest precedence, although this is not as clear in the doc as it should be. Your expression is parsed as ((1,2)+3),. Parentheses have the highest precedence. The combination of both facts is why tuples often need to be parenthesized, as it should be here and why you added the first pair instead of writing 1,2 + 3,. Disassembly of bytecode shows how an expression was parsed. from dis import dis dis('(1,2)+3,') 1 0 LOAD_CONST 3 ((1, 2)) 3 LOAD_CONST 2 (3) 6 BINARY_ADD 7 BUILD_TUPLE 1 10 RETURN_VALUE -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Project-wide variable...
On 6/23/2011 11:49 PM, Gnarlodious wrote: Let me restate my question. Say I have a script Executable.py that calls all other scripts and controls them: #!/usr/local/bin/python from Module import Data import ModuleTest ModuleTest.py has this: print(Data.Plist.Structure) Running Executable.py gives me this: NameError: name 'Data' is not defined 1) Can I tell Executable.py to share Data with ModuleTest.py? After the import is complete, yes. import ModuleTest ModuleTest.Data = Data This works if the use of Data is inside a function that is not called during import, not if the use of Data is at toplevel or in a class statement outside a def. or if that can't be done: 2) Can I tell ModuleTest.py to look upstream for Data? Yes if ModuleTest imports Executable, but circular imports are a bad idea. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
reg: playing with the list
Hey all, I am new here and new to python too. In general new to programming . I was working on aproblem. and need some help. I have a list of numbers say [2,3,5,6,10,15] which all divide number 30. Now i have to reduce this list to the numbers which are prime in number. i.e. [2,3,5] can somebody suggest? K -- http://mail.python.org/mailman/listinfo/python-list
Re: search through this list's email archives
En Thu, 23 Jun 2011 13:11:32 -0300, Cathy James nambo...@gmail.com escribió: I looked through this forum's archives, but I can't find a way to search for a topic through the archive. Am I missing something? Gmane provides a search capability also: http://blog.gmane.org/gmane.comp.python.general -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Interpreting Left to right?
Terry Reedy wrote: On 6/24/2011 12:32 AM, Chetan Harjani wrote: x=y=some string And we know that python interprets from left to right. Read the doc. 5.14. Evaluation order Python evaluates expressions from left to right. Notice that while evaluating an assignment, the right-hand side is evaluated before the left-hand side. The example given to me when I had this question: -- x = x['huh'] = {} -- x {'huh': {...}} As you can see, the creation of the dictionary is evaluated, and bound to the name 'x'; then the key 'huh' is set to the same dictionary. If you try that the other way 'round this happens: x['huh'] = x = {} Traceback (most recent call last): File stdin, line 1, in module NameError: name 'x' is not defined So -- the RHS (right hand side) gets evaluated first, then the LHSs from left to right. ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: User Authentication
Anurag wrote: My application is a web based application for both windows and Linux. The web part is developed using Django. So if Python does not support it then any support for local sytem account authentication in Django? I am looking for a common library for both Linux and Windows. Any help will be Gr8 Doesn't Django provide an abstraction layer for accessing differnt authentication backends? I guess you have to write/use two different authentication modules for the two different mechanisms. A quick search looks promising: http://www.google.com/search?q=django+ldap+authentication Ciao, Michael. -- http://mail.python.org/mailman/listinfo/python-list
Looking PDF module
Hello Everyone, I'm looking a good PDF module for Python 2.x - I've never used any PDF in Python, I don't know, what would be a good choice. There are several PDF tool for Python - this is my problem :) What I need: - utf8 support - create header and footer - (in headers there are small images) - tables - left and right side handling (this will be a book) - various page numbering (eg.: I/1, I/2, ... or simple numeric form) - TOC generating Any help would comes well, thanks: a. -- http://mail.python.org/mailman/listinfo/python-list
Re: Mac OS X 10.6.6 and MacPyhton 2.6 idle doesn't work
I took MacPython 2.6 from here: http://www.python.org/ftp/python/2.6.6/python-2.6.6-macosx10.3.dmg Also I downloaded Tcl/Tk from here http://www.kyngchaos.com/software/frameworks to using the gis software Qgis May be here the issue? -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 2.7 and cmd on Windows 7 64 (files lost)
Therefore, Windows has a trick for mark the file like visible, or not, in 32 mode. What trick? It's called file system redirection. When you access \windows\system32 in a 32-bit process, you *actually* access \windows\syswow64, which has entirely different files. The same also happens for parts of the registry. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking PDF module
Take a look to reportlab: http://www.reportlab.com/software/opensource/ Bye bye Luca -- http://mail.python.org/mailman/listinfo/python-list
Re: Interpreting Left to right?
On Fri, Jun 24, 2011 at 5:14 PM, Ethan Furman et...@stoneleaf.us wrote: -- x = x['huh'] = {} -- x {'huh': {...}} I would have to call that dodgy practice... unless you have a lot of places where you need a dictionary with itself as an element, I would avoid assignments that depend on each other. Perhaps it's just because I'm a C programmer, but that code smells a lot like the classic i = i++; blunder - nearly as bad as land wars in Asia. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: those darn exceptions
Chris Torek wrote: I can then check the now-valid pid via os.kill(). However, it turns out that one form of trash is a pid that does not fit within sys.maxint. This was a surprise that turned up only in testing, and even then, only because I happened to try a ridiculously large value as one of my test cases. It appears that this situation is not unique to os.kill(), for example, import os os.read(, 42) Traceback (most recent call last): File stdin, line 1, in module OverflowError: Python int too large to convert to C long In fact I'd expect it to happen any time you pass a very large int to something that's wrapping a C function. You can't really blame the wrappers for this -- it's not reasonable to expect all of them to catch out-of-range ints and do whatever the underlying function would have done if it were given an invalid argument. I think the lesson to take from this is that you should probably add OverflowError to the list of things to catch whenever you're calling a function with input that's not fully validated. -- Greg -- http://mail.python.org/mailman/listinfo/python-list
how to write to registry without admin rights on win vista/7
Hello, In my program I can set to run after system startup (it writes path to Software\Microsoft\Windows\CurrentVersion\Run) but when normal user is logged in my application crashes. I must right click on app an choose Run As Admin and then everything works. How can I do it to write to registry without Run As Admin ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking PDF module
hello, On Fri, Jun 24, 2011 at 12:37:40AM -0700, mando wrote: Take a look to reportlab: http://www.reportlab.com/software/opensource/ thanks, I'll check it out, a. -- http://mail.python.org/mailman/listinfo/python-list
Re: Interpreting Left to right?
Now its all clear. Thanks @ethan .. ur example is really scary. I didnt understand ur example fully although. See this is what i take it as: x=x['huh']={} first python checks check that there are two = operators. so it evaluates the RHS(since for = it is RHS to LHS) experession of right most (why is that?) now it assigns that experrsion({...}) to x the left most as u said first RHS to LHS then LHS to RHS. then it assigns x to to x['huh']. huh!!, ryt? may be it doesnt make sense but i guess this is the only way to actually not raise an error. Where am I wrong? On Fri, Jun 24, 2011 at 10:02 AM, Chetan Harjani chetan.harj...@gmail.comwrote: x=y=some string And we know that python interprets from left to right. so why it doesnt raise a name error here saying name 'y' is not defined? another example: (1,2) + 3, here, python raises a TypeError can only concatenate tuple(not int) to tuple but we know (3,) is a tuple as seen by following: t=3, type(t) type 'tuple' Arent both of this contradicting? -- Chetan H Harjani -- Chetan H Harjani -- http://mail.python.org/mailman/listinfo/python-list
Re: how to write to registry without admin rights on win vista/7
miamia peterirbi...@gmail.com wrote: Hello, In my program I can set to run after system startup (it writes path to Software\Microsoft\Windows\CurrentVersion\Run) but when normal user is logged in my application crashes. I must right click on app an choose Run As Admin and then everything works. How can I do it to write to registry without Run As Admin ? This might give you some pointers: http://stackoverflow.com/questions/130763/request-uac-elevation-from-within-a-python-script -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: LDAP: How get all users belongs to a group.
sajuptpm wrote: How get all users belongs to a group using python ldap module. There are several ways of storing grouping information in a LDAP server. I assume the groups are normal group entries of object class 'groupOfNames' which is most commonly used. Such an entry has the attribute 'member' which contains DNs of all member entries which you would have to read yourself. This can be quite annoying for large group entries since you would have to send a search request for each group member. Therefore on some servers you can search for a back-link attribute in the user entries. Most times it's called 'memberOf' or 'isMemberOf'. But this depends on the server's implemented features and configuration. Which LDAP server are you using? Ciao, Michael. -- http://mail.python.org/mailman/listinfo/python-list
Re: LDAP: How get all users belongs to a group.
Hi, Thanks for reply. dn: cn=My-Group-1, ou=Groups, o=CUST equivalentToMe: cn=TDS7034,ou=Internal PCA,o=CUST objectClass: groupOfNames objectClass: top objectClass: swarePointers ACL: 2#entry#[Root]#member cn: My-Group-1 member: cn=AJP2203,ou=Internal PCA,o=CUST member: cn=AZE9632,ou=Internal PCA,o=CUST member: cn=BTC4979,ou=Internal PCA,o=CUST * I have group definition in LDAP server as above. * How fetch all members from this perticular group 'My-Group-1' using python-ldap module. * I tried, but i don't know how do it. * I want to get those 3 members from group 'My-Group-' -- http://mail.python.org/mailman/listinfo/python-list
Re: LDAP: How get all users belongs to a group.
I am using Openldap (openldap 2.3.43-12.el5_5.2 and openldap.i386 0:2.3.43_2.2.29-12.el5_6.7) -- http://mail.python.org/mailman/listinfo/python-list
Re: Question regarding DNS resolution in urllib2
Michael Hrivnak wrote: The latest libcurl includes the CURLOPTS_RESOLVE option (http://curl.haxx.se/libcurl/c/curl_easy_setopt.html) that will do what you want. It may not have made its way into pycurl yet, but you could just call the command-line curl binary with the --resolve option. This feature was introduced in version 7.21.3. Michael Hey Michael , Thanks for the response . Thats exactly what i was looking for. curl binary with the --resolve ? --(0) curl --resolve curl: option --resolve: is unknown curl: try 'curl --help' or 'curl --manual' for more information --(saurabhve@sa-mac-saurabh)-(~)-- --(2) curl -V curl 7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8l zlib/1.2.3 Couldn't find it . ~saurabh -- http://mail.python.org/mailman/listinfo/python-list
Want to build an app for linux
Hi all , May be I'm just asking a silly/old question . I have some open web APIs which i can use , on it I want to develop an desktop application , probably cross platform but mostly I'm aiming at *unix platforms . I've got no experience in programming desktop application , but thats not a issue , I can do it . But i need to know right technology stack i could thinking of using. python or may be java or python/QT or google chrome platform. May be someone can suggest me some online tutorials/references , or any help appreciated. Thanks in advance ~saurabh -- http://mail.python.org/mailman/listinfo/python-list
Re: LDAP: How get all users belongs to a group.
--- User cn=AJP2203,ou=Internal PCA,o=CUST has group memberships to the following Groups: groupMembership: cn=My-Group-1,ou=Groups,o=CUST groupMembership: cn=My-Group-2,u=Groups,o=CUST groupMembership: cn=My-Group-3,ou=Groups,o=CUST --- Group dn: cn=My-Group-1, ou=Groups, o=CUST equivalentToMe: cn=TDS7034,ou=Internal PCA,o=CUST objectClass: groupOfNames objectClass: top objectClass: swarePointers ACL: 2#entry#[Root]#member cn: My-Group-1 member: cn=AJP2203,ou=Internal PCA,o=CUST member: cn=AZE9632,ou=Internal PCA,o=CUST member: cn=BTC4979,ou=Internal PCA,o=CUST - * We will get groups of a member from member record, using key 'groupMembership'. * But i want to get members belogs to a particular group Eg:'My- Group-1' * Have any method in python-ldap model for this ??? -- http://mail.python.org/mailman/listinfo/python-list
Re: Want to build an app for linux
On Fri, 2011-06-24 at 15:55 +0530, saurabh verma wrote: Hi all , May be I'm just asking a silly/old question . I have some open web APIs which i can use , on it I want to develop an desktop application , probably cross platform but mostly I'm aiming at *unix platforms . I've got no experience in programming desktop application , but thats not a issue , I can do it . But i need to know right technology stack i could thinking of using. python or may be java or python/QT or google chrome platform. May be someone can suggest me some online tutorials/references , or any help appreciated. I've found Python + Gtk (which includes Glade) to be a very productive solution. http://pygtk.org/ http://www.pygtk.org/articles/application-pygtk-glade/Building_an_Application_with_PyGTK_and_Glade.htm -- http://mail.python.org/mailman/listinfo/python-list
Re: Want to build an app for linux
Adam Tauno Williams wrote: On Fri, 2011-06-24 at 15:55 +0530, saurabh verma wrote: Hi all , May be I'm just asking a silly/old question . I have some open web APIs which i can use , on it I want to develop an desktop application , probably cross platform but mostly I'm aiming at *unix platforms . I've got no experience in programming desktop application , but thats not a issue , I can do it . But i need to know right technology stack i could thinking of using. python or may be java or python/QT or google chrome platform. May be someone can suggest me some online tutorials/references , or any help appreciated. I've found Python + Gtk (which includes Glade) to be a very productive solution. http://pygtk.org/ http://www.pygtk.org/articles/application-pygtk-glade/Building_an_Application_with_PyGTK_and_Glade.htm Hmm thanks for the response adam , I'll definitely check it out. Quick question : Is creating jazzy UI feasible with python + gtk ? like round shaped corners , color schemes etc etc. ~saurabh -- http://mail.python.org/mailman/listinfo/python-list
Re: LDAP: How get all users belongs to a group.
sajuptpm wrote: --- User cn=AJP2203,ou=Internal PCA,o=CUST has group memberships to the following Groups: groupMembership: cn=My-Group-1,ou=Groups,o=CUST groupMembership: cn=My-Group-2,u=Groups,o=CUST groupMembership: cn=My-Group-3,ou=Groups,o=CUST --- Group dn: cn=My-Group-1, ou=Groups, o=CUST equivalentToMe: cn=TDS7034,ou=Internal PCA,o=CUST objectClass: groupOfNames objectClass: top objectClass: swarePointers ACL: 2#entry#[Root]#member cn: My-Group-1 member: cn=AJP2203,ou=Internal PCA,o=CUST member: cn=AZE9632,ou=Internal PCA,o=CUST member: cn=BTC4979,ou=Internal PCA,o=CUST - * We will get groups of a member from member record, using key 'groupMembership'. * But i want to get members belogs to a particular group Eg:'My- Group-1' If this is the server's data the LDAP server seems to be Novell eDirectory not OpenLDAP. I'd try member search with this filter: (groupMembership=cn=My-Group-1,ou=Groups,o=CUST) Ciao, Michael. -- http://mail.python.org/mailman/listinfo/python-list
Re: Want to build an app for linux
On Fri, Jun 24, 2011 at 4:24 PM, Anthony Papillion papill...@gmail.comwrote: Hi Saurabh, I'm an experienced developer with quite a few years invested in both desktop and web development. But up until a few weeks ago, I'd really never touched Python much less developed a desktop app in it. I can tell you that the absolute easiest way to get started is this stack: PyGTK Glade Python Using those tools you'll be able to quickly learn to build desktop apps in Python with *very* little stress. Hope this helps and welcome to the list! hey anthony thanks for the help , Yes its definitely helpful . I have got two recommendations for pygtk/glade :) . I surely will be taking a deep dive in it very soon. ~saurabh -- http://mail.python.org/mailman/listinfo/python-list
Binary neural network in Python
Hello, I,m new in Python, I want to design and train a binary neural network classifiers in Python. This model of neural network should make preprocessing expert system model to deal with the original telecommunications alarms. *The model can be seen as the simplest kind of feed-**forward neural network which contains three inputs, six link **weights, two neuron and two outputs*. This model uses two important techniques, of which the time window technique is used for converting original alarms into transactions, and the neural network technique can classify the alarms with different levels according to the characteristics of telecommunication networks in order to mine the weighted association rules. Can anyone guide me, from where can I get some useful material/eBook/libraries etc. for the same (maybe there is source code already written?). I have no prior experience in neural netwoks and want to implement it urgently. Thanks in advance :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Project-wide variable...
On Jun 24, 12:27 am, Terry Reedy wrote: 1) Can I tell Executable.py to share Data with ModuleTest.py? After the import is complete, yes. import ModuleTest ModuleTest.Data = Data This works if the use of Data is inside a function that is not called during import, not if the use of Data is at toplevel or in a class statement outside a def. That works! The solution looks like this: # controlling program: from Module import Data import ModuleTest ModuleTest.Data = Data ModuleTest.getData() # module: def getData(): print(Data.Plist.Structure) Thanks for all your help! -- Gnarlie -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking PDF module
You might also want to have a look at Pisa ( http://www.xhtml2pdf.com/ ) . It's based on reportlab but might suit you better. -- http://mail.python.org/mailman/listinfo/python-list
Re: Want to build an app for linux
Adam Tauno Williams wrote: On Fri, 2011-06-24 at 15:55 +0530, saurabh verma wrote: Hi all , May be I'm just asking a silly/old question . I have some open web APIs which i can use , on it I want to develop an desktop application , probably cross platform but mostly I'm aiming at *unix platforms . I've got no experience in programming desktop application , but thats not a issue , I can do it . But i need to know right technology stack i could thinking of using. python or may be java or python/QT or google chrome platform. May be someone can suggest me some online tutorials/references , or any help appreciated. I've found Python + Gtk (which includes Glade) to be a very productive solution. http://pygtk.org/ http://www.pygtk.org/articles/application-pygtk-glade/Building_an_Application_with_PyGTK_and_Glade.htm I prefer QT and you have qt-creator: http://qt.nokia.com/products/developer-tools and PyQT/SIP: http://www.riverbankcomputing.co.uk/software/pyqt/intro IMHO you will get a better looking thing than with gtk2. -- //Aho -- http://mail.python.org/mailman/listinfo/python-list
Re: Want to build an app for linux
saurabh verma wrote: Quick question : Is creating jazzy UI feasible with python + gtk ? like round shaped corners , color schemes etc etc. Button shapes and colors are generally done in themes and luckily people using QT/gtk2 are allowed to change themes themselves which makes that the apps they use looks as they wish and not how a dictator want them to look (mainly thinking of mr gates and co). -- //Aho -- http://mail.python.org/mailman/listinfo/python-list
Re: Want to build an app for linux
I prefer QT and you have qt-creator: http://qt.nokia.com/products/developer-tools and PyQT/SIP: http://www.riverbankcomputing.co.uk/software/pyqt/intro IMHO you will get a better looking thing than with gtk2. Thanks Aho , Will surely look into it . -- http://mail.python.org/mailman/listinfo/python-list
Re: Want to build an app for linux
J.O. Aho wrote: saurabh verma wrote: Quick question : Is creating jazzy UI feasible with python + gtk ? like round shaped corners , color schemes etc etc. Button shapes and colors are generally done in themes and luckily people using QT/gtk2 are allowed to change themes themselves which makes that the apps they use looks as they wish and not how a dictator want them to look (mainly thinking of mr gates and co). Thats really informative tip. ~saurabh -- http://mail.python.org/mailman/listinfo/python-list
Re: reg: playing with the list
On 24-Jun-11 03:01 AM, kaustubh joshi wrote: Hey all, I am new here and new to python too. In general new to programming . I was working on aproblem. and need some help. I have a list of numbers say [2,3,5,6,10,15] which all divide number 30. Now i have to reduce this list to the numbers which are prime in number. i.e. [2,3,5] can somebody suggest? K You might try writing the boolean function is_prime(n) for almost any n. There was a recent discussion on this topic. Colin W. -- http://mail.python.org/mailman/listinfo/python-list
WORK FROM HOME - EARN $15,000 WEEKLY ( PART TIME JOBS)
WORK FROM HOME - EARN $15,000 WEEKLY ( PART TIME JOBS) REGISTER NOW START EARNING AT http://www.work8home.com -- http://mail.python.org/mailman/listinfo/python-list
Re: reg: playing with the list
You might try writing the boolean function is_prime(n) for almost any n. There was a recent discussion on this topic. Since the guy is new in programming, I complete the answer, just in case. Using the function is_prime(n), FIRST POSSIBILITY : new_list=[] for n in old_list: if is_prime(n): new_list.append(n) SECOND POSSIBILITY : new_list=[ n for n in old_list if is_prime(n) ] There is a primiality test in Sage which is basically a module over python (www.sagemath.org). Have a good WE Laurent -- http://mail.python.org/mailman/listinfo/python-list
Re: search through this list's email archives
On 2011-06-24, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: En Thu, 23 Jun 2011 13:11:32 -0300, Cathy James nambo...@gmail.com escribi?: I looked through this forum's archives, but I can't find a way to search for a topic through the archive. Am I missing something? Gmane provides a search capability also: http://blog.gmane.org/gmane.comp.python.general FWIW, I've found the Gmane search feature to be very unreliable. It often overlooks a lot of matching articles for no apparent reason. -- Grant Edwards grant.b.edwardsYow! Were these parsnips at CORRECTLY MARINATED in gmail.comTACO SAUCE? -- http://mail.python.org/mailman/listinfo/python-list
Re: reg: playing with the list
On Fri, Jun 24, 2011 at 8:01 AM, kaustubh joshi kandrjo...@gmail.com wrote: Hey all, I am new here and new to python too. In general new to programming . I was working on aproblem. and need some help. I have a list of numbers say [2,3,5,6,10,15] which all divide number 30. Now i have to reduce this list to the numbers which are prime in number. i.e. [2,3,5] can somebody suggest? Well, you can use a built-in function called filter to create a list containing only values that meet a certain need, for example, this will filter out everything that is even and put it into a new list - numbers = [1,2,3,4] def is_even(n): return n%2==0 # returns true if even, false if not. filter(is_even,numbers) [2, 4] All you need to do is to create or adapt an algorithm that tests whether a number is prime or not, and use that along with filter on your list of numbers. Several examples exist, it's quite a popular question. HTH. Noah. -- http://mail.python.org/mailman/listinfo/python-list
Re: LDAP: How get all users belongs to a group.
In 34110eed-96bc-499f-9a4e-068f2720f...@h12g2000pro.googlegroups.com sajuptpm sajup...@gmail.com writes: dn: cn=My-Group-1,ou=Groups,o=CUST member: cn=AJP2203,ou=Internal PCA,o=CUST member: cn=AZE9632,ou=Internal PCA,o=CUST member: cn=BTC4979,ou=Internal PCA,o=CUST * I have group definition in LDAP server as above. * How fetch all members from this perticular group 'My-Group-1' using python-ldap module. * I tried, but i don't know how do it. * I want to get those 3 members from group 'My-Group-' This code should work, although I haven't tested it: import ldap uri = my hostname and port user = my username password = my password ldapClient = ldap.initialize(uri) ldapClient.set_option(ldap.OPT_REFERRALS, 0) ldapClient.bind(user, password) results = ldapClient.search_s(cn=My-Group-1,ou=Groups,o=CUST, ldap.SCOPE_BASE) for result in results: result_dn = result[0] result_attrs = result[1] if member in result_attrs: for member in result_attrs[member]: print member ldapClient.unbind_s() -- John Gordon A is for Amy, who fell down the stairs gor...@panix.com B is for Basil, assaulted by bears -- Edward Gorey, The Gashlycrumb Tinies -- http://mail.python.org/mailman/listinfo/python-list
unzip problem
Hi, I am getting following error message while unziping a .zip file. Any help or idea is highly appreciated. Error message Traceback (most recent call last): File C:\Zip_Process\py\test2_new.py, line 15, in module outfile.write(z.read(name)) IOError: (22, 'Invalid argument') The script is here: * fh = open('T:\\test\\*.zip', 'rb') z = zipfile.ZipFile(fh) for name in z.namelist(): outfile = open(name, 'wb') outfile.write(z.read(name)) print z print outfile outfile.close() fh.close() winmail.dat-- http://mail.python.org/mailman/listinfo/python-list
Re: unzip problem
On Fri, 24 Jun 2011 10:55:52 -0400, Ahmed, Shakir wrote: Hi, I am getting following error message while unziping a .zip file. Any help or idea is highly appreciated. How do you know it is when unzipping the file? Maybe it is, or maybe it isn't. The line giving the error has *two* IO operations, a read and a write. Either one could give IOError. outfile.write(z.read(name)) IOError: (22, 'Invalid argument') The first thing is to isolate what is causing the error: data = z.read(name) outfile.write(data) Now you can be sure whether it is the read or the write which causes the error. Secondly, find out what the argument is. Assuming it is the read, try this: print repr(name) Can you open the zip file in Winzip or some other zip utility? Does it need a password? I see you do this: fh = open('T:\\test\\*.zip', 'rb') Do you really have a file called *.zip? I find that very hard to believe... as I understand it, * is a reserved character in Windows and you cannot have a file with that name. My guess is that the actual error is when you try to open the file in the first place, before any unzipping takes place, but you've messed up the line numbers (probably by editing the file after importing it). -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: unzip problem
On Jun 24, 2011, at 10:55 AM, Ahmed, Shakir wrote: Hi, I am getting following error message while unziping a .zip file. Any help or idea is highly appreciated. Error message Traceback (most recent call last): File C:\Zip_Process\py\test2_new.py, line 15, in module outfile.write(z.read(name)) IOError: (22, 'Invalid argument') Start debugging with these two steps -- 1) Add this just after for name in z.namelist(): print name That way you can tell which file is failing. 2) You can't tell whether you're getting an error on the write or the read because you've got two statements combined into one line. Change this -- outfile.write(z.read(name)) to this -- data = z.read(name) outfile.write(data) Good luck Philip The script is here: * fh = open('T:\\test\\*.zip', 'rb') z = zipfile.ZipFile(fh) for name in z.namelist(): outfile = open(name, 'wb') outfile.write(z.read(name)) print z print outfile outfile.close() fh.close() winmail.dat-- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking PDF module
On Jun 24, 6:45 am, neil.suffi...@gmail.com neil.suffi...@gmail.com wrote: You might also want to have a look at Pisa (http://www.xhtml2pdf.com/ ) . It's based on reportlab but might suit you better. There's more to the story. As with many things, the answer is, it depends. In this case, there are so many variables that I probably should write up an article outlining the pertinent ones ... Hegedüs Ervin, it's quite likely that ReportLab will be a good technical fit for you. Are you in a position to pay licensing fees for advanced features? Do you have any requirements to *merge* PDF instances? How stringent are your performance requirements? -- http://mail.python.org/mailman/listinfo/python-list
RE: unzip problem
On Fri, 24 Jun 2011 10:55:52 -0400, Ahmed, Shakir wrote: Hi, I am getting following error message while unziping a .zip file. Any help or idea is highly appreciated. How do you know it is when unzipping the file? Maybe it is, or maybe it isn't. The line giving the error has *two* IO operations, a read and a write. Either one could give IOError. outfile.write(z.read(name)) IOError: (22, 'Invalid argument') The first thing is to isolate what is causing the error: data = z.read(name) outfile.write(data) Now you can be sure whether it is the read or the write which causes the error. Secondly, find out what the argument is. Assuming it is the read, try this: print repr(name) Can you open the zip file in Winzip or some other zip utility? Does it need a password? I see you do this: fh = open('T:\\test\\*.zip', 'rb') Do you really have a file called *.zip? I find that very hard to believe... as I understand it, * is a reserved character in Windows and you cannot have a file with that name. My guess is that the actual error is when you try to open the file in the first place, before any unzipping takes place, but you've messed up the line numbers (probably by editing the file after importing it). -- Steven The problem is happening when it is coming to write option. The * is not the real name of the zip file, I just hide the name. -- http://mail.python.org/mailman/listinfo/python-list
RE: unzip problem
-Original Message- From: python-list-bounces+shahmed=sfwmd@python.org [mailto:python-list-bounces+shahmed=sfwmd@python.org] On Behalf Of Philip Semanchuk Sent: Friday, June 24, 2011 11:18 AM To: Lista-Comp-Lang-Python list Subject: Re: unzip problem On Jun 24, 2011, at 10:55 AM, Ahmed, Shakir wrote: Hi, I am getting following error message while unziping a .zip file. Any help or idea is highly appreciated. Error message Traceback (most recent call last): File C:\Zip_Process\py\test2_new.py, line 15, in module outfile.write(z.read(name)) IOError: (22, 'Invalid argument') Start debugging with these two steps -- 1) Add this just after for name in z.namelist(): print name That way you can tell which file is failing. 2) You can't tell whether you're getting an error on the write or the read because you've got two statements combined into one line. Change this -- outfile.write(z.read(name)) to this -- data = z.read(name) outfile.write(data) Good luck Philip The script is here: * fh = open('T:\\test\\*.zip', 'rb') z = zipfile.ZipFile(fh) for name in z.namelist(): outfile = open(name, 'wb') outfile.write(z.read(name)) print z print outfile outfile.close() fh.close() The problem found in outfile.Write. The error code is here and is happening when few of the files are already unzipped from the zip file T:\applications\tst\py\Zip_Process drg100.aux zipfile.ZipFile instance at 0x00E2F648 open file 'drg100.aux', mode 'wb' at 0x00E12608 drg100.fgdc.htm zipfile.ZipFile instance at 0x00E2F648 open file 'drg100.fgdc.htm', mode 'wb' at 0x00E128D8 drg100.htm zipfile.ZipFile instance at 0x00E2F648 open file 'drg100.htm', mode 'wb' at 0x00E12608 drg100.sdw zipfile.ZipFile instance at 0x00E2F648 open file 'drg100.sdw', mode 'wb' at 0x00E128D8 drg100.sid Unhandled exception while debugging... Traceback (most recent call last): File C:\Zip_Process\py\test2_new.py, line 16, in module outfile.write(data) IOError: (22, 'Invalid argument') -- http://mail.python.org/mailman/listinfo/python-list
Re: unzip problem
Ahmed, Shakir wrote: Hi, I am getting following error message while unziping a .zip file. Any help or idea is highly appreciated. Error message Traceback (most recent call last): File C:\Zip_Process\py\test2_new.py, line 15, in module outfile.write(z.read(name)) IOError: (22, 'Invalid argument') I just dealt with this problem on my system -- only pops up when writing large files (just over 50Mb for me) to a network drive; no problems when writing to a local drive. Here's how I get around it: CHUNK_SIZE = 10 * 1024 * 1024 fn = open(uncompressed_file, 'wb') ptr = 0 size = len(data) while ptr size: fn.write(data[ptr:ptr+CHUNK_SIZE]) ptr += CHUNK_SIZE fn.close() ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
RE: unzip problem
Ahmed, Shakir wrote: The problem is happening when it is coming to write option. The * is not the real name of the zip file, I just hide the name. Please don't waste our time by showing us fake code that doesn't do what you say it does. You said that The script is here, but that was not true, was it? What you showed us was not the script you were running. What other changes, deliberate or accidental, did you make? If you are going to edit the script to make it simpler (a good idea!), please run it first to make sure you still get the same error. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
python overloading
Not sure, this is the right place, redirect me if it's not. I was curious about the functionoverloading( http://svn.python.org/view/sandbox/trunk/overload/) and was trying to do a svn checkout of the branch and failed. Is it restricted access for even checkout? How do i get read-only access? == Anand Jeyahar http://sites.google.com/a/cbcs.ac.in/students/anand == The man who is really serious, with the urge to find out what truth is, has no style at all. He lives only in what is. ~Bruce Lee Love is a trade with lousy accounting policies. ~Aang Jie -- http://mail.python.org/mailman/listinfo/python-list
Re: those darn exceptions
Chris Torek wrote: I can then check the now-valid pid via os.kill(). However, it turns out that one form of trash is a pid that does not fit within sys.maxint. This was a surprise that turned up only in testing, and even then, only because I happened to try a ridiculously large value as one of my test cases. In article 96itucfad...@mid.individual.net Gregory Ewing greg.ew...@canterbury.ac.nz wrote: It appears that this situation is not unique to os.kill(), for example, import os os.read(, 42) Traceback (most recent call last): File stdin, line 1, in module OverflowError: Python int too large to convert to C long In fact I'd expect it to happen any time you pass a very large int to something that's wrapping a C function. You can't really blame the wrappers for this -- it's not reasonable to expect all of them to catch out-of-range ints and do whatever the underlying function would have done if it were given an invalid argument. I think the lesson to take from this is that you should probably add OverflowError to the list of things to catch whenever you're calling a function with input that's not fully validated. Indeed. (Provided that your call is the point at which the validation should occur -- otherwise, let the exception flow upwards as usual.) But again, this is why I would like to have the ability to use some sort of automated tool, where one can point at any given line of code and ask: what exceptions do you, my faithful tool, believe can be raised as a consequence of this line of code? If you point it at the call to main(): if __name__ == '__main__': main() then you are likely to get a useless answer (why, any exception at all); but if you point it at a call to os.read(), then you get one that is useful -- and tells you (or me) about the OverflowError. If you point it at a call to len(x), then the tool tells you what it knows about type(x) and x.__len__. (This last may well be nothing: some tools have only limited application. However, if the call to len(x) is preceded by an assert isinstance(x, (some,fixed,set,of,types)) for instance, or if all calls to the function that in turn calls len(x) are visible and the type of x can be proven, the tool might tell you something useful agin.) It is clear at this point that a simple list (or tuple) of possible exceptions is insufficient -- the tool has to learn, somehow, that len() raises TypeError itself, but also raises whatever x.__len__ raises (where x is the parameter to len()). If I ever get around to attempting this in pylint (in my Copious Spare Time no doubt :-) ), I will have to start with an external mapping from built in function F to exceptions that F raises and figure out an appropriate format for the table's entries. That is about half the point of this discussion (to provoke thought about how one might express this); the other half is to note that the documentation could probably be improved (as someone else already noted elsethread). Note that, if nothing else, the tool -- even in limited form, without the kind of type inference that pylint attempts -- gives you the ability to automate part of the documentation process. -- In-Real-Life: Chris Torek, Wind River Systems Intel require I note that my opinions are not those of WRS or Intel Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html -- http://mail.python.org/mailman/listinfo/python-list
Re: unzip problem
Ahmed, Shakir wrote: Thanks for your help and really appreciate your time. I changed the code as you mentioned and here it is: fn = open('T:\\applications\\tst\\py\\Zip_Process\\Zip\\myzip.zip', 'rb') z = zipfile.ZipFile(fn) for name in z.namelist(): data = z.read(name) ptr = 0 size = len(name) # change this back to data ^- No. You need the size of the data read in from the zipfile for that name, not the length of the name. Sorry for the omission. print size print ptr while ptr size: fn.write(name[ptr:ptr+CHUNK_SIZE]) # change name to data ptr += CHUNK_SIZE fn.close() ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: how to write to registry without admin rights on win vista/7
On 2011.06.24 03:48 AM, Duncan Booth wrote: http://stackoverflow.com/questions/130763/request-uac-elevation-from-within-a-python-script Heh. On Windows 7, using 'runas' for the operation in os.startfile() gives me a normal UAC prompt. Is there any way to ask for elevation from a subprocess.Popen() call? Launching an application that normally asks for elevation automatically fails with error 740 - 'The requested operation requires elevation'. The runas utility needs an explicit username. -- http://mail.python.org/mailman/listinfo/python-list
Re: NEED HELP-process words in a text file
Chris Rebert wrote: Netiquette comment: Please avoid SHOUTING The brilliant beam of light that first thought capitilized words amounted to shouting never programmed cobol, fortran, or pl/1 in the 1960s or 1970s :-) How or why this behavior was cultivated and continues to spread is mind boggling to me :-) -- Stanley C. Kitching Human Being Phoenix, Arizona -- http://mail.python.org/mailman/listinfo/python-list
Re: unzip problem
Ahmed, Shakir wrote: Thanks once again and you are right I am trying to unzip in the network share drive. here is the script now: If I am doing any wrong. : ## code start here import zipfile import os import time dir1 = T:\\applications\\tst\\py\\Zip_Process test = '%s/shp'%dir1 os.chdir(test) cwd = os.getcwd() print cwd CHUNK_SIZE = 10 * 1024 * 1024 fn = open('T:\\applications\\tst\\py\\Zip_Process\\Zip\\myzip.zip', 'rb') z = zipfile.ZipFile(fn) for name in z.namelist(): ptr = 0 data = z.read(name) size = len(data) print size print ptr while ptr size: fn.write(data[ptr:ptr+CHUNK_SIZE]) ptr += CHUNK_SIZE fn.close() #Code done here. But got error as follows: T:\applications\tst\py\Zip_Process\shp 59160 0 Traceback (most recent call last): File C:\Python25\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py , line 325, in RunScript exec codeObject in __main__.__dict__ File t:\scratch\shahmed\test2_new.py, line 24, in module fn.write(data[ptr:ptr+CHUNK_SIZE]) IOError: [Errno 9] Bad file descriptor I didn't notice this in your last post, but you are using fn as both the zipfile name and the name of the file you are writing to. You'll need to create the file you want to write before you write to it (plus any intermediate directories). Here's the (slightly stripped) version I actually use: 8 import os from zipfile import ZipFile def retrieve_files(zipped, destination, files=None): retrieves files from zipped CHUNK_SIZE = 10 * 1024 * 1024 try: os.makedirs(destination) except WindowsError: pass target = ZipFile(zipped, 'r') stored = dict([(k.filename.lower(), k.filename) for k in target.infolist()]) if files is None: files = [member.filename.lower() for member in target.infolist()] elif isinstance(files, (str, unicode)): files = [files.lower()] else: files = [f.lower() for f in files] for compressed_file in files: uncompressed_file = os.path.join(destination, compressed_file) path, filename = os.path.split(uncompressed_file) if not os.path.exists(path): os.makedirs(path) if filename == '__empty__': continue data = target.read(stored[compressed_file]) fn = open(uncompressed_file, 'wb') ptr = 0 size = len(data) while ptr size: fn.write(data[ptr:ptr+CHUNK_SIZE]) ptr += CHUNK_SIZE fn.close() target.close() 8 I convert all filenames to lower case since MS Windows doesn't care, but Python does. The test for filename == '__empty__': when I create the zipfile, if the directory is empty I store a 0-length file named '__empty__' in that subdirectory (actually, it only happens in the zipfile) so that I can get the directory back later. Hope this helps. ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: NEED HELP-process words in a text file
In iu2ns9$kkq$1...@dont-email.me Cousin Stanley cousinstan...@gmail.com writes: How or why this behavior was cultivated and continues to spread is mind boggling The behavior of writing in all caps, or the behavior of equating such writing with shouting? -- John Gordon A is for Amy, who fell down the stairs gor...@panix.com B is for Basil, assaulted by bears -- Edward Gorey, The Gashlycrumb Tinies -- http://mail.python.org/mailman/listinfo/python-list
Re: Interpreting Left to right?
On Fri, Jun 24, 2011 at 12:14:27AM -0700, Ethan Furman wrote: The example given to me when I had this question: -- x = x['huh'] = {} -- x {'huh': {...}} As you can see, the creation of the dictionary is evaluated, and bound to the name 'x'; then the key 'huh' is set to the same dictionary. Can you please elaborate? I really don't understand how this works at all. I would have expected a NameError from this (obviously my mental model is wrong). This single line is equivalent to: x = {} x['huh'] = x ...but I don't understand how python's evaluation semantics get from the one liner to the two liner/result at all. \t -- http://mail.python.org/mailman/listinfo/python-list
Re: Interpreting Left to right?
Tycho Andersen wrote: On Fri, Jun 24, 2011 at 12:14:27AM -0700, Ethan Furman wrote: The example given to me when I had this question: -- x = x['huh'] = {} -- x {'huh': {...}} As you can see, the creation of the dictionary is evaluated, and bound to the name 'x'; then the key 'huh' is set to the same dictionary. Can you please elaborate? I really don't understand how this works at all. I would have expected a NameError from this (obviously my mental model is wrong). This single line is equivalent to: x = {} x['huh'] = x ...but I don't understand how python's evaluation semantics get from the one liner to the two liner/result at all. \t Think of it this way: x = x['huh'] = {} obj = {} # RHS evaluated first (and only once) x = obj# then first LHS x['huh'] = obj # then second LHS, etc ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
RE: unzip problem - solved
-Original Message- From: Ethan Furman [mailto:et...@stoneleaf.us] Sent: Friday, June 24, 2011 3:47 PM To: Ahmed, Shakir Cc: Python Subject: Re: unzip problem Ahmed, Shakir wrote: Thanks once again and you are right I am trying to unzip in the network share drive. here is the script now: If I am doing any wrong. : ## code start here import zipfile import os import time dir1 = T:\\applications\\tst\\py\\Zip_Process test = '%s/shp'%dir1 os.chdir(test) cwd = os.getcwd() print cwd CHUNK_SIZE = 10 * 1024 * 1024 fn = open('T:\\applications\\tst\\py\\Zip_Process\\Zip\\myzip.zip', 'rb') z = zipfile.ZipFile(fn) for name in z.namelist(): ptr = 0 data = z.read(name) size = len(data) print size print ptr while ptr size: fn.write(data[ptr:ptr+CHUNK_SIZE]) ptr += CHUNK_SIZE fn.close() #Code done here. But got error as follows: T:\applications\tst\py\Zip_Process\shp 59160 0 Traceback (most recent call last): File C:\Python25\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py , line 325, in RunScript exec codeObject in __main__.__dict__ File t:\scratch\shahmed\test2_new.py, line 24, in module fn.write(data[ptr:ptr+CHUNK_SIZE]) IOError: [Errno 9] Bad file descriptor I didn't notice this in your last post, but you are using fn as both the zipfile name and the name of the file you are writing to. You'll need to create the file you want to write before you write to it (plus any intermediate directories). Here's the (slightly stripped) version I actually use: 8 import os from zipfile import ZipFile def retrieve_files(zipped, destination, files=None): retrieves files from zipped CHUNK_SIZE = 10 * 1024 * 1024 try: os.makedirs(destination) except WindowsError: pass target = ZipFile(zipped, 'r') stored = dict([(k.filename.lower(), k.filename) for k in target.infolist()]) if files is None: files = [member.filename.lower() for member in target.infolist()] elif isinstance(files, (str, unicode)): files = [files.lower()] else: files = [f.lower() for f in files] for compressed_file in files: uncompressed_file = os.path.join(destination, compressed_file) path, filename = os.path.split(uncompressed_file) if not os.path.exists(path): os.makedirs(path) if filename == '__empty__': continue data = target.read(stored[compressed_file]) fn = open(uncompressed_file, 'wb') ptr = 0 size = len(data) while ptr size: fn.write(data[ptr:ptr+CHUNK_SIZE]) ptr += CHUNK_SIZE fn.close() target.close() 8 I convert all filenames to lower case since MS Windows doesn't care, but Python does. The test for filename == '__empty__': when I create the zipfile, if the directory is empty I store a 0-length file named '__empty__' in that subdirectory (actually, it only happens in the zipfile) so that I can get the directory back later. Hope this helps. ~Ethan~ Thanks a lot to Ethan who really helped to find out the clue in the code. Here is the final code that worked to unzip a large file in the network drive. CHUNK_SIZE = 10 * 1024 * 1024 fh = open('T:\\applications\\tst\\py\\Zip_Process\\Zip\\myzip.zip', 'rb') z = zipfile.ZipFile(fh) for name in z.namelist(): fn = open(name, 'wb') ptr = 0 data = z.read(name) size = len(name) print size print ptr while ptr size: #fn.write(data) fn.write(data[ptr:ptr+CHUNK_SIZE]) ptr += CHUNK_SIZE fn.close() fh.close() -- http://mail.python.org/mailman/listinfo/python-list
Re: Interpreting Left to right?
On Fri, Jun 24, 2011 at 01:13:08PM -0700, Ethan Furman wrote: Tycho Andersen wrote: On Fri, Jun 24, 2011 at 12:14:27AM -0700, Ethan Furman wrote: The example given to me when I had this question: -- x = x['huh'] = {} -- x {'huh': {...}} As you can see, the creation of the dictionary is evaluated, and bound to the name 'x'; then the key 'huh' is set to the same dictionary. Can you please elaborate? I really don't understand how this works at all. I would have expected a NameError from this (obviously my mental model is wrong). This single line is equivalent to: x = {} x['huh'] = x ...but I don't understand how python's evaluation semantics get from the one liner to the two liner/result at all. \t Think of it this way: x = x['huh'] = {} obj = {} # RHS evaluated first (and only once) x = obj# then first LHS x['huh'] = obj # then second LHS, etc Yes, I understand that, but I guess I don't understand *why* things are done that way. What is the evaluation order principle at work here? I would have expected: tmp = {} x['huh'] = tmp # NameEror! That is, the right hand sides of assignments are evaluated before the left hand sides. That is (somehow?) not the case here. \t -- http://mail.python.org/mailman/listinfo/python-list
Re: unzip problem - solved
Ahmed, Shakir wrote: Here is the final code that worked to unzip a large file in the network drive. CHUNK_SIZE = 10 * 1024 * 1024 fh = open('T:\\applications\\tst\\py\\Zip_Process\\Zip\\myzip.zip', 'rb') z = zipfile.ZipFile(fh) for name in z.namelist(): fn = open(name, 'wb') ptr = 0 data = z.read(name) size = len(name) print size print ptr while ptr size: #fn.write(data) fn.write(data[ptr:ptr+CHUNK_SIZE]) ptr += CHUNK_SIZE fn.close() fh.close() The 'size = len(name)' should be 'size = len(data)'. ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Significant figures calculation
Hi, I am looking for an easy way to do significant figure calculations in python (which I want to use with a class that does unit calculations). Significant figure calculations should have the semantics explained, e.g., here: http://chemistry.about.com/od/mathsciencefundamentals/a/sigfigures.htm My hope was that the decimal module would provide this functionality, but: print Decimal('32.01') + Decimal(5.325) + Decimal('12') 49.335 # instead of 49 print Decimal('25.624') / Decimal('25') 1.02496 # instead of 1.0 print Decimal('1.2') == Decimal('1.23') False # actually not sure how the semantics should be I tried to modify the DecimalContext (e.g. getcontext().prec = 2) but that did not lead to the correct behavior. Google and this list didn't yield a good answer yet... so I'd be happy to get a good recommendations or pointers. P.S. I am aware that significant figure calculation is controversial and makes implicit assumptions on the probability distributions of the variables. I am simply looking for an implementation of the (well defined) arithmetics as defined on the cited website. -- http://mail.python.org/mailman/listinfo/python-list
Re: Interpreting Left to right?
In article 20110624200618.gk6...@point.cs.wisc.edu, Tycho Andersen ty...@tycho.ws wrote: Yes, I understand that, but I guess I don't understand *why* things are done that way. What is the evaluation order principle at work here? I would have expected: tmp = {} x['huh'] = tmp # NameEror! That is, the right hand sides of assignments are evaluated before the left hand sides. That is (somehow?) not the case here. http://docs.python.org/py3k/reference/simple_stmts.html#assignment-statem ents -- Ned Deily, n...@acm.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Significant figures calculation
On Fri, 24 Jun 2011 13:05:41 -0700, Harold wrote: Hi, I am looking for an easy way to do significant figure calculations in python (which I want to use with a class that does unit calculations). Significant figure calculations should have the semantics explained, e.g., here: http://chemistry.about.com/od/mathsciencefundamentals/a/sigfigures.htm My hope was that the decimal module would provide this functionality, but: print Decimal('32.01') + Decimal(5.325) + Decimal('12') 49.335 # instead of 49 print Decimal('25.624') / Decimal('25') 1.02496 # instead of 1.0 print Decimal('1.2') == Decimal('1.23') False # actually not sure how the semantics should be I tried to modify the DecimalContext (e.g. getcontext().prec = 2) but that did not lead to the correct behavior. Really? It works for me. import decimal D = decimal.Decimal decimal.getcontext().prec = 2 D('32.01') + D('5.325') + D('12') Decimal('49') D('25.624') / D('25') Decimal('1.0') The only thing you have to watch out for is this: D('1.2') == D('1.23') # no rounding False D('1.2') == +D('1.23') # force rounding True -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Significant figures calculation
On Fri, Jun 24, 2011 at 4:46 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: Really? It works for me. import decimal D = decimal.Decimal decimal.getcontext().prec = 2 D('32.01') + D('5.325') + D('12') Decimal('49') I'm curious. Is there a way to get the number of significant digits for a particular Decimal instance? I spent a few minutes browsing through the docs, and didn't see anything obvious. I was thinking about setting the precision dynamically within a function, based on the significance of the inputs. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: Mac OS X 10.6.6 and MacPyhton 2.6 idle doesn't work
In article 09cae8bf-4b1f-40ea-af36-4ba130c41...@m18g2000vbl.googlegroups.com, mando mandol...@gmail.com wrote: I took MacPython 2.6 from here: http://www.python.org/ftp/python/2.6.6/python-2.6.6-macosx10.3.dmg Also I downloaded Tcl/Tk from here http://www.kyngchaos.com/software/frameworks to using the gis software Qgis May be here the issue? I can't reproduce the problem and I really don't see how installing that Tcl/Tk framework could cause the problem by itself. The version of Tcl and Tk to dynamically load is added to the executable at link time when the installer is being built. It should look something like this: $ cd /Library/Frameworks/Python.framework/Versions/2.6 $ cd ./lib/python2.6/lib-dynload/ $ otool -L _tkinter.so _tkinter.so (architecture ppc): /Library/Frameworks/Tcl.framework/Versions/8.4/Tcl (compatibility version 8.4.0, current version 8.4.19) /Library/Frameworks/Tk.framework/Versions/8.4/Tk (compatibility version 8.4.0, current version 8.4.19) /usr/lib/libmx.A.dylib (compatibility version 1.0.0, current version 47.1.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 88.3.10) _tkinter.so (architecture i386): /Library/Frameworks/Tcl.framework/Versions/8.4/Tcl (compatibility version 8.4.0, current version 8.4.19) /Library/Frameworks/Tk.framework/Versions/8.4/Tk (compatibility version 8.4.0, current version 8.4.19) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 88.3.10) Note the absolute path to the framework. If that version of the framework does not exist at that location, the dynamic loader falls back to the OS X standard location /System/Library/Frameworks ... If you've only installed that one extra Tcl/Tk version, things should look something like this: $ ls -l /Library/Frameworks/Tcl.framework/Versions/ total 8 drwxr-xr-x 5 root admin 272 Jul 27 2010 8.5/ lrwxr-xr-x 1 root admin3 Jun 24 13:31 Current@ - 8.5 $ ls -l /Library/Frameworks/Tk.framework/Versions/ total 8 drwxr-xr-x 5 root admin 272 Jul 27 2010 8.5/ lrwxr-xr-x 1 sysadminold wheel3 Jun 24 13:31 Current@ - 8.5 $ ls -l /System/Library/Frameworks/Tk.framework/Versions/ total 8 drwxr-xr-x 5 root wheel 340 Mar 17 18:27 8.4/ drwxr-xr-x 5 root wheel 340 Mar 17 18:27 8.5/ lrwxr-xr-x 1 root wheel3 Nov 7 2010 Current@ - 8.5 $ ls -l /System/Library/Frameworks/Tcl.framework/Versions/ total 8 drwxr-xr-x 5 root wheel 374 Mar 17 18:27 8.4/ drwxr-xr-x 5 root wheel 374 Mar 17 18:27 8.5/ lrwxr-xr-x 1 root wheel3 Nov 7 2010 Current@ - 8.5 If not, something's wrong. It's especially odd that you would see a problem with IDLE.app since it is not influenced by shell initialization steps. Do you have something set in ~/.MacOSX/environment.plist ? Also, try launching that idle from a shell: $ /usr/local/bin/idle2.6 -- Ned Deily, n...@acm.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Interpreting Left to right?
On 6/24/2011 4:06 PM, Tycho Andersen wrote: tmp = {} x['huh'] = tmp # NameEror! That is, the right hand sides of assignments are evaluated before the left hand sides. That is (somehow?) not the case here. You are parsing a = b = c as a = (b = c) which works in a language in which assignment is an expression, but does not work in Python where assignment is a statement. You have to parse it more as (a = b) = c but that does not work since then the first '=' is not what it seems. It is more like (both a and b) = c. Perhaps best to expand a = b = c to a = c; b = c and see the first as an abbreviation thereof -- just delete the 'c;'. If I have ever used this sort of multiple assignment, it has been for simple unambiguous things like a = b = 0. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Interpreting Left to right?
On Fri, Jun 24, 2011 at 01:24:24PM -0700, Ned Deily wrote: In article 20110624200618.gk6...@point.cs.wisc.edu, Tycho Andersen ty...@tycho.ws wrote: Yes, I understand that, but I guess I don't understand *why* things are done that way. What is the evaluation order principle at work here? I would have expected: tmp = {} x['huh'] = tmp # NameEror! That is, the right hand sides of assignments are evaluated before the left hand sides. That is (somehow?) not the case here. http://docs.python.org/py3k/reference/simple_stmts.html#assignment-statements Perhaps I'm thick, but (the first thing I did was read the docs and) I still don't get it. From the docs: An assignment statement evaluates the expression list (remember that this can be a single expression or a comma-separated list, the latter yielding a tuple) and assigns the single resulting object to each of the target lists, from left to right. For a single target, it evaluates the RHS and assigns the result to the LHS. Thus x = x['foo'] = {} first evaluates x['foo'] = {} which should raise a NameError, since x doesn't exist yet. Where am I going wrong? Thanks, \t -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking PDF module
hello, On Fri, Jun 24, 2011 at 09:59:17AM -0700, Cameron Laird wrote: Hegedüs Ervin, it's quite likely that ReportLab will be a good technical fit for you. it's a good news :) Are you in a position to pay licensing fees for advanced features? no :( Do you have any requirements to *merge* PDF instances? may be, hope I don't, but currently I don't know, How stringent are your performance requirements? there isn't stringent... thanks: a. -- http://mail.python.org/mailman/listinfo/python-list
Re: Project-wide variable...
On 6/24/2011 7:30 AM, Gnarlodious wrote: On Jun 24, 12:27 am, Terry Reedy wrote: 1) Can I tell Executable.py to share Data with ModuleTest.py? After the import is complete, yes. import ModuleTest ModuleTest.Data = Data This works if the use of Data is inside a function that is not called during import, not if the use of Data is at toplevel or in a class statement outside a def. That works! The solution looks like this: # controlling program: from Module import Data import ModuleTest ModuleTest.Data = Data ModuleTest.getData() # module: def getData(): print(Data.Plist.Structure) This is a form of dependency injection, where a caller injects into a callee a dependency (callee) of the callee. It can be used even if the callee imports a dependency when it is imported. It is useful for testing when you want the callee to use a different dependency for testing. Simple example: # MyModule import socket def myconnect(*args): ... socket.bind() # Test_MyModule import mock_socket import MyModule MyModule.socket = mock_socket ... test of MyModule, including MyModule.myconnect Python makes this trivial without requiring that the otherwise constant depedency always be injected or passed (in normal production use) as a variable. In your case, you are free to inject different forms of Data if you wish. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Interpreting Left to right?
On Fri, Jun 24, 2011 at 05:02:00PM -0400, Terry Reedy wrote: On 6/24/2011 4:06 PM, Tycho Andersen wrote: tmp = {} x['huh'] = tmp # NameEror! That is, the right hand sides of assignments are evaluated before the left hand sides. That is (somehow?) not the case here. You are parsing a = b = c as a = (b = c) which works in a language in which assignment is an expression, but does not work in Python where assignment is a statement. You have to parse it more as (a = b) = c but that does not work since then the first '=' is not what it seems. It is more like (both a and b) = c. Perhaps best to expand a = b = c to a = c; b = c and see the first as an abbreviation thereof -- just delete the 'c;'. If I have ever used this sort of multiple assignment, it has been for simple unambiguous things like a = b = 0. Ah, the point about the grammar is what I was missing. Thanks a bunch! \t -- http://mail.python.org/mailman/listinfo/python-list
Re: python overloading
On 6/24/2011 2:01 PM, anand jeyahar wrote: Not sure, this is the right place, redirect me if it's not. I was curious about the functionoverloading(http://svn.python.org/view/sandbox/trunk/overload/) and was trying to do a svn checkout of the branch and failed. Is it restricted access for even checkout? How do i get read-only access? I believe that exact link is for web viewing. What was your exact svn or tortoise svn command? -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: NEED HELP-process words in a text file
John Gordon wrote: In iu2ns9$kkq$1...@dont-email.me Cousin Stanley cousinstan...@gmail.com writes: How or why this behavior was cultivated and continues to spread is mind boggling The behavior of writing in all caps, or the behavior of equating such writing with shouting ? The latter equating writing in all caps with shouting It wobbles the mind. -- Stanley C. Kitching Human Being Phoenix, Arizona -- http://mail.python.org/mailman/listinfo/python-list
Re: search through this list's email archives
En Fri, 24 Jun 2011 11:33:23 -0300, Grant Edwards invalid@invalid.invalid escribió: On 2011-06-24, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: En Thu, 23 Jun 2011 13:11:32 -0300, Cathy James nambo...@gmail.com escribi?: I looked through this forum's archives, but I can't find a way to search for a topic through the archive. Am I missing something? Gmane provides a search capability also: http://blog.gmane.org/gmane.comp.python.general FWIW, I've found the Gmane search feature to be very unreliable. It often overlooks a lot of matching articles for no apparent reason. It seems no single provider is perfect. Google searching capability is quite good, but for some reason, many posts are missing, often the initial post head of a thread. The Python-URL summaries usually include a Google Groups url, but sometimes I have to link to Gmane, velocityreviews.com or even to the list archives at python.org because of that problem. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Interpreting Left to right?
In article 20110624210835.gl6...@point.cs.wisc.edu, Tycho Andersen ty...@tycho.ws wrote: On Fri, Jun 24, 2011 at 01:24:24PM -0700, Ned Deily wrote: In article 20110624200618.gk6...@point.cs.wisc.edu, Tycho Andersen ty...@tycho.ws wrote: Yes, I understand that, but I guess I don't understand *why* things are done that way. What is the evaluation order principle at work here? I would have expected: tmp = {} x['huh'] = tmp # NameEror! That is, the right hand sides of assignments are evaluated before the left hand sides. That is (somehow?) not the case here. http://docs.python.org/py3k/reference/simple_stmts.html#assignment-statement s Perhaps I'm thick, but (the first thing I did was read the docs and) I still don't get it. From the docs: An assignment statement evaluates the expression list (remember that this can be a single expression or a comma-separated list, the latter yielding a tuple) and assigns the single resulting object to each of the target lists, from left to right. For a single target, it evaluates the RHS and assigns the result to the LHS. Thus x = x['foo'] = {} first evaluates x['foo'] = {} which should raise a NameError, since x doesn't exist yet. Where am I going wrong? An assignment statement evaluates the expression list (remember that this can be a single expression or a comma-separated list, the latter yielding a tuple) and assigns the single resulting object to each of the target lists, from left to right. Also, remember that in Python the = is not part of an expression. It's a token in the assignment statement. -- Ned Deily, n...@acm.org -- http://mail.python.org/mailman/listinfo/python-list
Re: how to write to registry without admin rights on win vista/7
On 2011.06.24 03:48 AM, Duncan Booth wrote: http://stackoverflow.com/questions/130763/request-uac-elevation-from-within-a-python-script Heh. On Windows 7, using 'runas' for the operation in os.startfile() gives me a normal UAC prompt. Is there any way to ask for elevation from a subprocess.Popen() call? Launching an application that normally automatically asks for elevation fails with error 740 - 'The requested operation requires elevation'. -- http://mail.python.org/mailman/listinfo/python-list
Re: NEED HELP-process words in a text file
On Fri, 24 Jun 2011 19:17:29 +, Cousin Stanley wrote: Chris Rebert wrote: Netiquette comment: Please avoid SHOUTING The brilliant beam of light that first thought capitilized words amounted to shouting never programmed cobol, fortran, or pl/1 in the 1960s or 1970s :-) That's probably because the use of capitalisation for emphasis pre-dates the invention of computers by centuries. It is hardly an accident that the technical term for uppercase is derived from the same root as majestic and major. The history of so-called minuscule and majuscule letters is complex, and it hasn't been a universal rule that Capital Letters have ALWAYS been read as emphatic, but it has been true for hundreds of years (at least for languages that have capital letters). Not the ONLY form of emphasis, of course (underlining, bold face, italics and l e t t e r - s p a c i n g are only a few of the other alternatives available), but in a plain-text medium with little control over the display of font, the use of lower and UPPER case letters is one of the few alternatives available. (The use of *markup* seems to have been a late invention in English, although in other languages it has been used much longer.) If ONE word in uppercase is read in a SLIGHTLY louder voice, then naturally it doesn't take much imagination TO READ EVEN QUITE SHORT PASSAGES OF UNINTERRUPTED UPPERCASE WORDS AS SHOUTING LOUDLY -- regardless of the poor design of programming languages in the 60s and 70s. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: those darn exceptions
Chris Torek nos...@torek.net writes: But again, this is why I would like to have the ability to use some sort of automated tool, where one can point at any given line of code and ask: what exceptions do you, my faithful tool, believe can be raised as a consequence of this line of code? “Why, any exception at all”. If you point it at the call to main(): if __name__ == '__main__': main() then you are likely to get a useless answer (why, any exception at all); but if you point it at a call to os.read(), then you get one that is useful -- and tells you (or me) about the OverflowError. No. The answer is *still* “why, any exception at all”. The name ‘os.read’ could be re-bound at run-time to any object at all, so a code checker that you “point at any given line of code” can't know what the name will be bound to when that line gets executed. If you point it at a call to len(x), then the tool tells you what it knows about type(x) and x.__len__. Which information, before the code is executed, isn't determined. -- \ “The cost of education is trivial compared to the cost of | `\ ignorance.” —Thomas Jefferson | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: Interpreting Left to right?
On Sat, Jun 25, 2011 at 7:02 AM, Terry Reedy tjre...@udel.edu wrote: If I have ever used this sort of multiple assignment, it has been for simple unambiguous things like a = b = 0. For which it's extremely useful. Initialize a whole bunch of variables to zero... or to a couple of values: minfoo=minbar=minquux=1000 maxfoo=maxbar=maxquux=0 There are times when I miss the assignment is an expression concept, but I'd say this syntax covers 90% or more of use cases for assignment expressions. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Significant figures calculation
Jerry Hill wrote: I'm curious. Is there a way to get the number of significant digits for a particular Decimal instance? I spent a few minutes browsing through the docs, and didn't see anything obvious. I was thinking about setting the precision dynamically within a function, based on the significance of the inputs. Not officially, so far as I know, but if you're willing to risk using a private implementation detail that is subject to change: decimal.Decimal('000123.45000')._int '12345000' However, sometimes you may need to inspect the exponent as well: zero = decimal.Decimal('0.') zero._int '0' zero._exp -8 -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Interpreting Left to right?
Tycho Andersen ty...@tycho.ws writes: On Fri, Jun 24, 2011 at 01:24:24PM -0700, Ned Deily wrote: http://docs.python.org/py3k/reference/simple_stmts.html#assignment-statements Perhaps I'm thick, but (the first thing I did was read the docs and) I still don't get it. From the docs: An assignment statement evaluates the expression list (remember that this can be a single expression or a comma-separated list, the latter yielding a tuple) and assigns the single resulting object to each of the target lists, from left to right. Notice that, in the grammar given there, there is exactly one “expression list”, following *all* of the ‘=’s. The “target lists” are each to the left of an ‘=’. For a single target, it evaluates the RHS and assigns the result to the LHS. Thus x = x['foo'] = {} first evaluates x['foo'] = {} No, that's not an “expression list” by the grammar given in the docs. The expression list consists, in your example, of “{}” only. The target lists are “x”, then “x['foo']”, in that order. -- \ “If consumers even know there's a DRM, what it is, and how it | `\ works, we've already failed.” —Peter Lee, Disney corporation, | _o__) 2005 | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: Interpreting Left to right?
On 6/24/2011 5:08 PM, Tycho Andersen wrote: An assignment statement evaluates the expression list (remember that this can be a single expression or a comma-separated list, the latter yielding a tuple) and assigns the single resulting object to each of the target lists, from left to right. This is the 'other' type of 'multiple assignment' a,b,c = 1,2,3 Order matters here too. a,a[1] = [1,2],3 a # [1,3] # but a[1], a = 3, [1,2] will either fail or modify what a was previously bound to before rebinding a to [1,2]. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Installing Python Apps on Mac Lion
The Lion version of the OS on the Mac comes with Python 2.7 installed, but it is in /System/Library/Frameworks/..., and this area is not writable by third party apps. So is there a consensus on what apps that typically install under the Python site-packages directory should do in this situation? Installing Python from python.org puts it in the writable area /Library/Frameworks/Python.framework. So, what should a Python app installer do? Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Significant figures calculation
I tried to modify the DecimalContext (e.g. getcontext().prec = 2) but that did not lead to the correct behavior. Really? It works for me. You are right, I did something wrong when attempting to set the precision. And the trick with rounding the decimal with the unary + is neat. It's the first time for me to play with decimals, so bare with me if I miss the obvious. However, this approach forces you to know the number of significant figures beforehand -- which is precisely what the arithmetics should do for you. What would indeed be nice, is Jerry's suggestion to obtain the number of significant bits and write a small wrapper around the number protocoll implementation that accounts significance and have __str__/__repr__ set the context dynamically. I haven't seen anything obvious in the docs, though it might be possible to use log10 of the length of some normalized string representation. -- http://mail.python.org/mailman/listinfo/python-list
what's the big deal for print()
Hi, Why people want print() instead of print str? That's not a big deal and the old choice is more natural. Anyone has some clue? -- http://mail.python.org/mailman/listinfo/python-list
Re: NEED HELP-process words in a text file
Steven D'Aprano wrote: On Fri, 24 Jun 2011 19:17:29 +, Cousin Stanley wrote: Chris Rebert wrote: Netiquette comment: Please avoid SHOUTING The brilliant beam of light that first thought capitilized words amounted to shouting never programmed cobol, fortran, or pl/1 in the 1960s or 1970s :-) That's probably because the use of capitalisation for emphasis pre-dates the invention of computers by centuries. It is hardly an accident that the technical term for uppercase is derived from the same root as majestic and major. The history of so-called minuscule and majuscule letters is complex, and it hasn't been a universal rule that Capital Letters have ALWAYS been read as emphatic, but it has been true for hundreds of years (at least for languages that have capital letters). Not the ONLY form of emphasis, of course (underlining, bold face, italics and l e t t e r - s p a c i n g are only a few of the other alternatives available), but in a plain-text medium with little control over the display of font, the use of lower and UPPER case letters is one of the few alternatives available. (The use of *markup* seems to have been a late invention in English, although in other languages it has been used much longer.) If ONE word in uppercase is read in a SLIGHTLY louder voice, then naturally it doesn't take much imagination TO READ EVEN QUITE SHORT PASSAGES OF UNINTERRUPTED UPPERCASE WORDS AS SHOUTING LOUDLY -- regardless of the poor design of programming languages in the 60s and 70s. Well said. :) ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: what's the big deal for print()
In d3558c5d-0fe6-4da7-843d-c2f45b2bf...@y13g2000yqy.googlegroups.com pipehappy pipeha...@gmail.com writes: Why people want print() instead of print str? That's not a big deal and the old choice is more natural. Anyone has some clue? Because the new Python uses print(). print str is the old way. -- John Gordon A is for Amy, who fell down the stairs gor...@panix.com B is for Basil, assaulted by bears -- Edward Gorey, The Gashlycrumb Tinies -- http://mail.python.org/mailman/listinfo/python-list
Re: what's the big deal for print()
On 6/24/2011 10:39 PM, pipehappy wrote: Hi, Why people want print() instead of print str? That's not a big deal and the old choice is more natural. Anyone has some clue? print as a function instead of a statement is consistent with input as a function, can be overridden with custom versions, can be passed to functions as an argument, and can have options passed as arguments instead of with terrible syntax hacks. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: those darn exceptions
On Sat, Jun 25, 2011 at 10:25 AM, Ben Finney ben+pyt...@benfinney.id.au wrote: No. The answer is *still* “why, any exception at all”. The name ‘os.read’ could be re-bound at run-time to any object at all, so a code checker that you “point at any given line of code” can't know what the name will be bound to when that line gets executed. Sure it can. And KeyboardInterrupt could be raised at any time, too. But this is a TOOL, not a deity. If Function X is known to call Function Y and built-in method Z, and also raises FooException, then X's list of most likely exceptions would be FooException + Y.__exceptions__ + Z.__exceptions__. It won't be perfect, but it'd be something that could go into an autodoc-style facility. Obviously you can fiddle with things, but in _ordinary usage_ this is what it's _most likely_ to produce. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list
Re: what's the big deal for print()
John Gordon wrote: In d3558c5d-0fe6-4da7-843d-c2f45b2bf...@y13g2000yqy.googlegroups.com pipehappy pipeha...@gmail.com writes: Why people want print() instead of print str? That's not a big deal and the old choice is more natural. Anyone has some clue? Because the new Python uses print(). print str is the old way. I think you missed the point of the question, which is, *why* does the new Python (version 3+) use a function print() instead of a statement? The problems with print as a statement includes: It requires special treatment in the compiler, instead of just being an ordinary function like len(), etc. It's hard to come up with special syntax to add extra functionality to print statement. Compare the ugly syntax needed to add support for printing to writable files in Python 2: print fileobj, arg # what does the mysterious syntax mean? compared to the natural way it works in Python 3: print(arg, file=fileobj) Likewise, changing the delimiter between arguments. Python 3 has: print(1, 2, 3, sep=*) 1*2*3 while Python 2 requires you to generate the string by hand, and then print it: print '*'.join('%s' % x for x in (1, 2, 3)) 1*2*3 One Frequently Asked Question is How do I get rid of the newline after printing? In Python 2, you leave a comma at the end of the print statement. What? A comma? How does that make *any* sense at all??? Unfortunately, while that gets rid of the newline, it also leaves spaces between items: def example(): ... print 1, ... print 2, ... print 3 ... example() 1 2 3 Here's the Python 3 version: def example(): ... print(1, sep='', end='') ... print(2, sep='', end='') ... print(3, sep='') ... example() 123 To get the same result in Python 2, you have to use sys.stdout.write(). The canonical explanation for why print is now a function is here: http://www.python.org/dev/peps/pep-3105/ -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Installing Python Apps on Mac Lion
In article 2ffee45b-8987-4fb4-8c8b-c1eed728e...@glegroupsg2000goo.googlegroups.com , JKPeck jkp...@gmail.com wrote: The Lion version of the OS on the Mac comes with Python 2.7 installed, but it is in /System/Library/Frameworks/..., and this area is not writable by third party apps. So is there a consensus on what apps that typically install under the Python site-packages directory should do in this situation? Installing Python from python.org puts it in the writable area /Library/Frameworks/Python.framework. So, what should a Python app installer do? I don't know about Lion but the Apple-supplied Pythons in previous versions of OS X (10.6 and 10.5) install site packages by default into /Library/Python. If you use the Distutils defaults with the system Pythons in10.7, they will likely do the same. -- Ned Deily, n...@acm.org -- http://mail.python.org/mailman/listinfo/python-list
Re: how to write to registry without admin rights on win vista/7
* miamia (Fri, 24 Jun 2011 01:08:55 -0700 (PDT)) In my program I can set to run after system startup (it writes path to Software\Microsoft\Windows\CurrentVersion\Run) Under HKLM oder HKCU? The path itself is of course irrelevant. but when normal user is logged in my application crashes. Without an exception? I must right click on app an choose Run As Admin and then everything works. How can I do it to write to registry without Run As Admin ? Disable UAC. Thorsten -- http://mail.python.org/mailman/listinfo/python-list
[issue12353] argparse cannot handle empty arguments
Torsten Landschoff t.landsch...@gmx.net added the comment: Your unit test isn't consistent with the other unit tests in that set, which makes me suspicious that it isn't testing what we need to test. That is because I did not try to understand the machinery behind the argparse unit tests completely. I did not want to create an extra unit test class just for this one test. Also, there are unit tests for this case further up in the test file (TestEmptyAndSpaceContainingArguments). I haven't been able to reproduce the bug. Did you run the unit tests from my patch? Can you post a short program that reproduces the failure? Here you go: from argparse import ArgumentParser parser = ArgumentParser(fromfile_prefix_chars=@) parser.parse_args([]) This gives me Traceback (most recent call last): File stdin, line 1, in module File /opt/python3/lib/python3.3/argparse.py, line 1726, in parse_args args, argv = self.parse_known_args(args, namespace) File /opt/python3/lib/python3.3/argparse.py, line 1758, in parse_known_args namespace, args = self._parse_known_args(args, namespace) File /opt/python3/lib/python3.3/argparse.py, line 1770, in _parse_known_args arg_strings = self._read_args_from_files(arg_strings) File /opt/python3/lib/python3.3/argparse.py, line 2003, in _read_args_from_files if arg_string[0] not in self.fromfile_prefix_chars: IndexError: string index out of range -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12353 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12353] argparse cannot handle empty arguments
Torsten Landschoff t.landsch...@gmx.net added the comment: Here is another possible patch that will catch the problem. But this enables the fromfile_prefix_chars option for all tests checking empty and space arguments. This way a problem that occurs only without that option might be hidden. We would need to run those tests with and without fromfile_prefix_chars. -- Added file: http://bugs.python.org/file22433/modify_test_empty.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12353 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11104] distutils sdist ignores MANIFEST
Stephen Thorne step...@thorne.id.au added the comment: I have 2 patches, with tests, that applies on python2.7 and the python3 series of branches, attached this ticket. I have also got a signed contributor agreement lodged with the PSF. Can I please have someone either apply my patches or tell me what I need to do in order to change them if they are being rejected. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11104 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12303] expose sigwaitinfo() and sigtimedwait() in the signal module
Ross Lagerwall rosslagerw...@gmail.com added the comment: Here's a patch to add the two functions (with docs and tests). You'll need to run autoreconf before compiling. -- assignee: - rosslagerwall keywords: +patch nosy: +rosslagerwall stage: - patch review type: - feature request Added file: http://bugs.python.org/file22434/issue12303.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12303 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11909] Doctest sees directives in strings when it should only see them in comments
Devin Jeanpierre jeanpierr...@gmail.com added the comment: You're right, and good catch. If a doctest starts with a #coding:XXX line, this should break. One option is to replace the call to tokenize.tokenize with a call to tokenize._tokenize and pass 'utf-8' as a parameter. Downside: that's a private and undocumented API. The alternative is to manually add a coding line that specifies UTF-8, so that any coding line in the doctest would be ignored. My preferred option would be to add the ability to read unicode to the tokenize API, and then use that. I can file a separate ticket if that sounds good, since it's probably useful to others too. One other thing to be worried about -- I'm not sure how doctest would treat tests with leading coding:XXX lines. I'd hope it ignores them, if it doesn't then this is more complicated and the above stuff wouldn't work. I'll see if I have the time to play around with this (and add more test cases to the patch, correspondingly) this weekend. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11909 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12361] Memory Leak in File Logging
Vinay Sajip vinay_sa...@yahoo.co.uk added the comment: Marked as pending since no further information is available. I will close this issue in two weeks unless more information becomes available; even after this, if you get more information, you can re-open this issue. Also please note that Python 2.6 is closed for changes other than security-related ones. -- status: open - pending ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12361 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12393] Packaging should provide support for extensible categories
New submission from Vinay Sajip vinay_sa...@yahoo.co.uk: Some installation locations are platform-dependent and cannot be categorised into a small but fixed number of categories. This is particularly true for the Windows ecosystem - PowerShell, Office, SharePoint all have specific locations where files need to be installed for interoperability with them. This can be catered for by a pre-hook for install_data, but some very small core changes are needed: 1. In the install_data constructor, initialise self.categories to an empty dictionary. 2. In install_data.expand_categories, add a local_vars.update(self.categories) after the local_vars = get_paths() statement. Just these small changes are sufficient to allow sufficient control over custom installation locations. For projects that need custom categories, they just need to do the necessary setup in an install_data pre-hook: def pre_install_data(cmd): cmd.categories['customcategory'] = '/path/for/my/custom/category' I have this working in the pythonv branch, and if the feature request is accepted I can work up a patch including changes to docs, tests etc. -- assignee: tarek components: Distutils2, Library (Lib) messages: 138895 nosy: alexis, eric.araujo, tarek, vinay.sajip priority: normal severity: normal status: open title: Packaging should provide support for extensible categories type: feature request versions: Python 3.3 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12393 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12394] Packaging should provide better support for executable scripts on Windows
New submission from Vinay Sajip vinay_sa...@yahoo.co.uk: At present, packaging support for scripts on Windows is the same as for any other system. This is sub-optimal, for the following reasons: 1. Windows doesn't support #! lines to find the correct executable for a script. On a system with multiple Python versions and scripts written for particular versions, support for locating the correct needs to be present. 2. Windows has two types of executables - console applications and GUI applications - and Windows users expect correct usage of either python.exe or pythonw.exe, depending on the individual script being run. Setuptools (and therefore Distribute) support these requirements by installing a script demo, on Windows, as demo.exe and demo-script.py (or demo-script.pyw), where demo.exe is a stock Windows executable (either console or GUI) which invokes the appropriate Python executable on the demo-script.py[w] file. Packaging should provide a similar mechanism, which can be implemented very simply by changing the build_scripts command appropriately. It should work like this: 1. When writing a script, the developer simply provides a #!line as normal, but if intended for deployment on Windows, ensures the executable is named as pythonw rather than python. The script should have no extension, as would be for case for a script Linux or OS X. 2. On Windows, the build-scripts command will build the script as it does now - substituting the correct executable for the #! line - but on Windows, instead of writing the script out as e.g. demo, it will write it as either demo-script.py or demo-script.pyw (depending on whether the #! line had pythonw in it or not), and will also write a stock executable (either console or GUI, depending) with the corresponding name demo.exe. 3. Since install_scripts just copies files from the build directory, there shouldn't need to be any changes here. The stock executables can be the same as Distribute uses (setuptools/cli.exe and setuptools/gui.exe), if there is no licensing (or other) issue with having them in Python. If there is such an issue, they can be written from scratch to do the same job (it's just one C file). I have this working in the pythonv branch, and if this feature request is accepted then I can work up a patch with test and doc changes. (The build_scripts changes are quite straightforward.) -- assignee: tarek components: Distutils2, Library (Lib) messages: 138896 nosy: alexis, eric.araujo, tarek, vinay.sajip priority: normal severity: normal status: open title: Packaging should provide better support for executable scripts on Windows type: feature request versions: Python 3.3 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12394 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12394] Packaging should provide better support for executable scripts on Windows
Tim Golden m...@timgolden.me.uk added the comment: Are you aware of PEP 397? http://www.python.org/dev/peps/pep-0397/ -- nosy: +tim.golden ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12394 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12303] expose sigwaitinfo() and sigtimedwait() in the signal module
STINNER Victor victor.stin...@haypocalc.com added the comment: Cool, a patch! Some comments. Why do you wait until the end of PyInit_signal() to set initialized to 1? If this variable is only present to call PyStructSequence_InitType() only once, you can set initialized to 1 directly in the if. Is it possible that PyInit_signal() is called more than once? C modules cannot be unloaded in Python, but I see that the init function of the posixmodule.c has also a static initialized variable. Doc: The sigwaitinfo()/sigtimedwait() manual page contains interesting infos: (If one of the signals in set is already pending for the calling thread, sigwaitinfo() will return immediately with information about that signal.) If both fields of this structure are specified as 0, a poll is performed: sigtimedwait() returns immediately, either with information about a signal that was pending for the caller, or with an error if none of the signals in set was pending. The manpage doesn't tell that the signal handler is not called, should we say it in the Python doc? Doc: you may add links between pause(), sigwait(), sigwaitinfo() and sigtimedwait() functions. We should maybe reorganise the signal doc to group functions. We need maybe a section for pending signals functions, functions to block or wait signals: pause(), pthread_sigmask(), sigpending(), sigwait(), sigwaitinfo(), sigtimedwait(). Another big theme of the signal module is signal handling. We may group functions by these two themes. Well, it is better to reorganize the doc is a second commit ;-) The timeout is a tuple. Usually, Python uses float for timeout (e.g. see select.select). I suppose that you chose a tuple to keep the precision of the timespec structure. We may accept both types: (sec: int, nanosec: int) or sec: float. It would be nice to have the opinion of our time expect, Alexander Belopolsky. It is possible to pass a negative timeout: the select() functions accepts or not negative timeout depending on the platform. In Python 3.3, select.select() now always raise an exception if the timeout is negative to have the same behaviour on all platforms. According to the Linux manual page, sigtimedwait() can return EINVAL if the timeout is invalid. We may also always raise an exception if the timeout is negative in sigtimedwait()? signal_sigwaitinfo() and signal_sigtimedwait() use iterable_to_sigset() whereas this function is only compiled if #if defined(PYPTHREAD_SIGMASK) || defined(HAVE_SIGWAIT). You have to fix this test. According to the manual page, sigwaitinfo() or sigtimedwait() can be interrupted (EINTR) by an unexpected signal (in signal not the signal set): you should call PyErr_CheckSignals(). You should add a test for this case. Your patch doesn't touch configure nor pyconfig.h.in, only configure.in. Edit configure manually (better to limit the size of the patch) and run autoheader to regenerate pyconfig.h.in (or maybe edit manually pyconfig.h.in). siginfo_t structure contains more fields, but I don't know if we need all of them. It can be improved later. sigtimedwait() raises a OSError(EGAIN) on timeout. The behaviour must be documented, or we can choose another behaviour. We may simply return None in case of a timeout, it is just more practical to use than a try/except. For example, threading.Lock.acquire(timeout) simply returns False in case of a timeout. select.select() returns ([], [], []) in case of a timeout, not an exception. test_sigtimedwait_timeout(): why do you call signal.alarm()? You may also add a test for timeout=0, I suppose that it is a special timeout value. I will do a deeper review on the second version of your patch :-) Thanks again for the patch. I tried to write it, but I was bored of the siginfo_t fields (too many fields, and I didn't know how to expose them in Python). -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12303 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com