ANN: python-ldap 2.4.11
Find a new release of python-ldap: http://pypi.python.org/pypi/python-ldap/2.4.11 python-ldap provides an object-oriented API to access LDAP directory servers from Python programs. It mainly wraps the OpenLDAP 2.x libs for that purpose. Additionally it contains modules for other LDAP-related stuff (e.g. processing LDIF, LDAP URLs and LDAPv3 schema). Project's web site: http://www.python-ldap.org/ Ciao, Michael. Released 2.4.11 2013-05-27 Changes since 2.4.10: Lib/ * ldap.controls.DecodeControlTuples() now simply ignores PyAsn1Error exception raised during decoding malformed response control values in case of non-critical controls. * ldif.LDIFWriter.unparse() does not simply skip empty records anymore. -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
SQLObject 1.3.3 and 1.4.1
Hello! I'm pleased to announce bugfix releases 1.3.3 and 1.4.1. What's new in SQLObject === * Fixed bugs in pickling and unpickling (remove/restore a weak proxy to self, fixed cache handling). * Added an example of using SQLObject with web.py to the links page. Contributors for this release are Andrew Trusty and Rhubarb Sin. For a more complete list, please see the news: http://sqlobject.org/News.html What is SQLObject = SQLObject is an object-relational mapper. Your database tables are described as classes, and rows are instances of those classes. SQLObject is meant to be easy to use and quick to get started with. SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite, Firebird, Sybase, MSSQL and MaxDB (also known as SAPDB). Where is SQLObject == Site: http://sqlobject.org Development: http://sqlobject.org/devel/ Mailing list: https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss Archives: http://news.gmane.org/gmane.comp.python.sqlobject Download: https://pypi.python.org/pypi/SQLObject/1.3.3 https://pypi.python.org/pypi/SQLObject/1.4.1 News and changes: http://sqlobject.org/News.html Oleg. -- Oleg Broytmanhttp://phdru.name/p...@phdru.name Programmers don't die, they just GOSUB without RETURN. -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
Re: Encodign issue in Python 3.3.1 (once again)
Τη Τρίτη, 28 Μαΐου 2013 1:18:06 π.μ. UTC+3, ο χρήστης Chris Angelico έγραψε: You're effectively asking people to put in a few minutes' work, sometimes quite a few minutes, to help you. Is it too much to hope that you'll spend one more minute on your posts? No it is not, you are right, i should be more careful when typing and spend some time to correct before i send my responses. I promise i will not overlook this as well as the blank line google imposes. As fo my initial question any comments-remarks? -- http://mail.python.org/mailman/listinfo/python-list
Re: I want to know how to implement concurrent threads in Python
On 28 May 2013 05:06, Daniel Gagliardi danielgagliardira...@gmail.com wrote: fuck! fuck! i'm gonna be fired if i didnt get this shit! i told my boss id do it. fuck! im gonna pipe some crakc. fuck... So do it. You've already been told how to. It's true that python does not do real concurrent execution, but if most of your threads spend most time sleeping, waiting on a socket or doing IO, those are opportunities for other threads to cut in and execute concurrently and the threading module is your best choice. If you need to do cpu-intensive tasks concurrently, use the multiprocessing module. -- http://mail.python.org/mailman/listinfo/python-list
Re: TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple'
Τη Κυριακή, 26 Μαΐου 2013 7:45:42 μ.μ. UTC+3, ο χρήστης Mark Lawrence έγραψε: What has this got to do with Python? What do your questions have to do with a proper reply? -- http://mail.python.org/mailman/listinfo/python-list
RE: Total Beginner - Extracting Data from a Database Online (Screenshot)
On 28 May 2013 02:21, Carlos Nepomuceno carlosnepomuc...@outlook.com wrote: Date: Mon, 27 May 2013 17:58:00 -0700 Subject: Re: Total Beginner - Extracting Data from a Database Online (Screenshot) From: logan.c.gra...@gmail.com To: python-list@python.org [...] Oh goodness, yes, I have no clue. For example: # to retrieve the contents of all column '# fb' (11th column from the image you sent) c11 = [tables[0][r][10] for r in range(len(tables[0]))] Or rather: c11 = [row[10] for row in tables[0]] In most cases, range(len(x)) is a sign that you're doing it wrong :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Python error codes and messages location
On 28 May 2013 05:17, Vito De Tullio vito.detul...@gmail.com wrote: Fábio Santos wrote: Speaking of PEPs and exceptions. When do we get localized exceptions? What do you mean by localized exceptions? Please, tell me it's *NOT* a proposal to send the exception message in the locale language! It is. I think I read it mentioned in python-dev or this list. Here is what I read. http://mail.python.org/pipermail/python-dev/2013-April/125364.html It wasn't only about exceptions after all. And it seems like something that will only happen far into the future. I really hope really far... have you never tried to google a localized error message? :\ -- By ZeD Never. I don't even try. I still think this is a good idea. Not for debugging though. For UI (and error logs if your requirements include writing them in the user language), it could simplify all the user-facing-unexpected-error-reporting into an except hook, or a try..except high up in your call stack. It would be a pretty big step towards RAD. But it had to be made optional somehow. Maybe using errno and existing exception messages together with gettext? -- http://mail.python.org/mailman/listinfo/python-list
Re: Future standard GUI library
On Tue, May 28, 2013 at 9:10 AM, Roy Smith r...@panix.com wrote: In article mailman.2265.1369693294.3114.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: I'll use XML when I have to, but if I'm inventing my own protocol, nope. There are just too many quirks with it. How do you represent an empty string named Foo? Foo/Foo or equivalently Foo/ How do you represent an empty list named Foo? The same way. How do you represent an empty dict/mapping named Foo? Lemme look up my documentation... ah, the same way. Does this seem right to you?/JubalEarly XML doesn't represent strings, or lists, or dicts. It represents trees of nodes with labels. If you wish to invent some richer semantic meaning to impose on those nodes, that's up to you. Sure it doesn't, but it's very often used that way. So I guess what I'm really saying is that XML is wrong for 90% of the places it's used. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Python error codes and messages location
On Tue, May 28, 2013 at 4:57 PM, Fábio Santos fabiosantos...@gmail.com wrote: On 28 May 2013 05:17, Vito De Tullio vito.detul...@gmail.com wrote: I really hope really far... have you never tried to google a localized error message? :\ Never. I don't even try. Same happens when someone pastes an error onto a mailing list like this. Unless there's some easily-identifiable token (maybe the exception type doesn't get localized, though that has its own consequences) by which everyone world-over can recognize the exception, this would be a major nuisance. Also, once the interpreter core and a few parts of the stdlib get localized, this would add a barrier to entry for new modules... not sure this is a good thing. Can we internationalize English instead of localizing Python? Not-entirely-joking-ly yours, ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Reading *.json from URL - json.loads() versus urllib.urlopen.readlines()
On 28 May 2013 04:19, Bryan Britten britten.br...@gmail.com wrote: I'm not familiar with using read(4096), I'll have to look into that. When I tried to just save the file, my computer just sat in limbo for some time and didn't seem to want to process the command. That's just file.read with an integer argument. You can read a file by chunks by repeatedly calling that function until you get the empty string. Based on my *extremely* limited knowledge of JSON, that's definitely the type of file this is. Here is a snippet of what is seen when you log in: ... That's json. It's pretty big, but not big enough to stall a slow computer more than half a second. - I've looked for documentation on that method on twitter. It seems that it's part of the twitter streaming api. https://dev.twitter.com/docs/streaming-apis What this means is that the requests aren't supposed to end. They are supposed to be read gradually, using the lines to split the response into meaningful chunks. That's why you can't read the data and why your browser never gets around to download it. Both urlopen and your browser block while waiting for the request to end. Here's more info on streaming requests on their docs: https://dev.twitter.com/docs/streaming-apis/processing For streaming requests in python, I would point you to the requests library, but I am not sure it handles streaming requests. -- http://mail.python.org/mailman/listinfo/python-list
Re: Ldap module and base64 oncoding
Joseph L. Casale wrote: I had some time today, so I attempted to open the ldif files in binary mode to simply work with the raw byte strings but the moment the first entry was parsed, parse() stumbled on a character in the first entries dict and passed a dn of None for the last half? Without seeing the LDIF data and your code I can't tell what's going on. If the option to avoid worrying about decoding and encoding could work, I would be happy to process the whole lot in byte strings. Any idea what may cause this? I would not claim that module 'ldif' has really awesome docs. But did you follow the example with LDIFParser in the docs? http://www.python-ldap.org/doc/html/ldif.html#example It illustrates that for LDIF stream processing one basically derives a class from ldif.LDIFParser overriding method handle(). The most basic test would be something like this: [..] def handle(self,dn,entry): print '***dn',repr(dn) pprint.pprint(entry) And then carefully look at the output. Ciao, Michael. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python error codes and messages location
On 28 May 2013 08:19, Chris Angelico ros...@gmail.com wrote: On Tue, May 28, 2013 at 4:57 PM, Fábio Santos fabiosantos...@gmail.com wrote: On 28 May 2013 05:17, Vito De Tullio vito.detul...@gmail.com wrote: I really hope really far... have you never tried to google a localized error message? :\ Never. I don't even try. Same happens when someone pastes an error onto a mailing list like this. Unless there's some easily-identifiable token (maybe the exception type doesn't get localized, though that has its own consequences) by which everyone world-over can recognize the exception, this would be a major nuisance. Just to clarify, I am suggesting to have the unchanged messages in tracebacks, but having some methods in the exception to get the exception and message localised. Just like repr() and str() are directed at different audiences (the programmer vs. The user), so is a traceback vs a message box. In English, we could translate the exception name (which is limited as a python name). EG. RuntimeError - Runtime error. Of course, this is not a big deal, but it would let us show the error message to the user, together with the exception. It would be much harder to search for an error or ask for help if it was a message written by some random developer. OpenERP for example shows stack traces to the user. It could show a shorter message in the user's language. Also, once the interpreter core and a few parts of the stdlib get localized, this would add a barrier to entry for new modules... not sure this is a good thing. I think that would be a job for a per-language team as opposed to someone implementing a bug fix or pushing a PEP? Even that would only be necessary for the exceptions a module raises. Can we internationalize English instead of localizing Python? That is worse than saying, why don't we all just code in python?. Or c. Or java. Or JavaScript. Let's not get into that. I prefer len() to new LengthCalculatorFactoryBuilder().createLengthCalculatorFactory().createLengthCalculator().calculateLengthOf(). And a good old Python list or JavaScript array to a collection of segfaults. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python error codes and messages location
On Tue, May 28, 2013 at 6:10 PM, Fábio Santos fabiosantos...@gmail.com wrote: Just to clarify, I am suggesting to have the unchanged messages in tracebacks, but having some methods in the exception to get the exception and message localised. Just like repr() and str() are directed at different audiences (the programmer vs. The user), so is a traceback vs a message box. There's no particular reason for that to be a method on the exception, then. You're just asking to localize a text string, and I think that functionality already exists someplace :) OpenERP for example shows stack traces to the user. It could show a shorter message in the user's language. Sounds like an OpenERP feature request, then. On 28 May 2013 08:19, Chris Angelico ros...@gmail.com wrote: Can we internationalize English instead of localizing Python? That is worse than saying, why don't we all just code in python?. Or c. Or java. Or JavaScript. Let's not get into that. I prefer len() to new LengthCalculatorFactoryBuilder().createLengthCalculatorFactory().createLengthCalculator().calculateLengthOf(). And a good old Python list or JavaScript array to a collection of segfaults. Yeah, like I said, that wasn't a serious suggestion :) ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: I want to know how to implement concurrent threads in Python
Am 26.05.2013 21:10, schrieb Daniel Gagliardi: I want to know how to implement concurrent threads in Python Have you tried searching the web or maybe looked on docs.python.org? Seriously, show at least some effort before asking here. Uli -- http://mail.python.org/mailman/listinfo/python-list
Re: Python error codes and messages location
On Tue, 28 May 2013 17:15:51 +1000, Chris Angelico wrote: Can we internationalize English instead of localizing Python? We have. English is the primary international language for programmers. (For which I am profoundly grateful.) Japanese is also a pretty important language, but mostly in Japan. And China would like Chinese to be, in fact there is even a version of Python localised to Chinese: http://www.chinesepython.org/ I have no objection to people creating their own, localised, implementation or fork of Python, in which case good luck to them but they're on their own. But I don't think that exceptions should otherwise be localised. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Short-circuit Logic
On Tuesday, May 28, 2013 2:10:05 AM UTC+2, Nobody wrote: On Mon, 27 May 2013 13:11:28 -0700, Ahmed Abdulshafy wrote: On Sunday, May 26, 2013 2:13:47 PM UTC+2, Steven D'Aprano wrote: What the above actually tests for is whether x is so small that (1.0+x) cannot be distinguished from 1.0, which is not the same thing. It is also quite arbitrary. Why 1.0? Why not (0.0001+x)? Or (0.0001+x)? Or (1.0+x)? That may be true for integers, What may be true for integers? but for floats, testing for equality is not always precise And your point is? What Steven wrote is entirely correct: sys.float_info.epsilon is the smallest value x such that 1.0 and 1.0+x have distinct floating-point representations. It has no relevance for comparing to zero. He just said that the way to test for zero equality is x == 0, and I meant that this is true for integers but not necessarily for floats. And that's not specific to Python. -- http://mail.python.org/mailman/listinfo/python-list
RE: Short-circuit Logic
Date: Tue, 28 May 2013 01:39:09 -0700 Subject: Re: Short-circuit Logic From: abdulsh...@gmail.com [...] What Steven wrote is entirely correct: sys.float_info.epsilon is the smallest value x such that 1.0 and 1.0+x have distinct floating-point representations. It has no relevance for comparing to zero. He just said that the way to test for zero equality is x == 0, and I meant that this is true for integers but not necessarily for floats. And that's not specific to Python. Have you read [1]? There's a section Infernal Zero that discuss this problem. I think it's very interesting to know! ;) Just my 49.98¢! lol [1] http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Future standard GUI library
Chris Angelico於 2013年5月28日星期二UTC+8下午3時11分55秒寫道: On Tue, May 28, 2013 at 9:10 AM, Roy Smith r...@panix.com wrote: In article mailman.2265.1369693294.3114.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: I'll use XML when I have to, but if I'm inventing my own protocol, nope. There are just too many quirks with it. How do you represent an empty string named Foo? Foo/Foo or equivalently Foo/ How do you represent an empty list named Foo? The same way. How do you represent an empty dict/mapping named Foo? Lemme look up my documentation... ah, the same way. Does this seem right to you?/JubalEarly XML doesn't represent strings, or lists, or dicts. It represents trees of nodes with labels. If you wish to invent some richer semantic meaning to impose on those nodes, that's up to you. Sure it doesn't, but it's very often used that way. So I guess what I'm really saying is that XML is wrong for 90% of the places it's used. ChrisA Please check the annual sales in Ebay or similar sites and the advertizement fees collected by Google and Yahoo. -- http://mail.python.org/mailman/listinfo/python-list
Re: Problems with python and pyQT
Thanks for your reply: very useful!! I have another question: with hex command i display (for example) 0x1 is it possible to display 0x01? Thanks Il giorno lunedì 27 maggio 2013 15:10:24 UTC+2, Chris “Kwpolska” Warrick ha scritto: On Mon, May 27, 2013 at 11:26 AM, silusilus...@gmail.com wrote: Hi, i'm new with python: so excuse me for my questions i have this code: def updateLog(self, text): self.ui.logTextEdit.moveCursor(QTextCursor.End) self.ui.logTextEdit.insertHtml(font color=\Black\+text) self.ui.logTextEdit.moveCursor(QTextCursor.End) logTextEdit is a QTextEdit object.With this code,i can display only ascii characters: how can i diplay text as hex and binary values? Thanks -- http://mail.python.org/mailman/listinfo/python-list You would need to convert them to strings first. You may want bin() and hex() for that. And if you want to convert 'q' to 0x71, hex(ord(q)). And if you want to turn 'hello' into 0x68656c6c6f, you would need to iterate over 'hello' and run the above function over every letter. Also, you are able to display Unicode characters, too. -- http://mail.python.org/mailman/listinfo/python-list
Python for IPSA (Power flow analysis)
Hi there, I am new to Python, and wondering if you could help me with python based coding for the IPSA (Power system analysis software). I have a electrical distribution network with generators, buses and loads, on which I am performing the load flow analysis every 1 hour for a period of 1 year. The code to perform instantaneous load/power flow analysis is given below. I need to modify it such that I can perform this load flow analysis every 1 hour for a period of 1 year. Please help. from ipsa import * ipsasys = IscInterface() net = ipsasys.ReadFile(refinery.iif) bok = net.DoLoadFlow(); if bok: busbars = net.GetBusbars() print Load Flow results: print print BusName Vmag(kV) print for bus in busbars.itervalues(): name = bus.GetName() vm = bus.GetVoltageMagnitudekV() res = %-8s %10.5f % (name, vm) print res else: print Load Flow failed! Regards, Debbie -- http://mail.python.org/mailman/listinfo/python-list
Re: Problems with python and pyQT
On 05/28/2013 05:41 AM, silusilus...@gmail.com wrote: Thanks for your reply: very useful!! I have another question: with hex command i display (for example) 0x1 is it possible to display 0x01? hex() is a function, not a command. And it only takes the one parameter, the int to be converted. For more generality, try the str.format() method. The x type converts to hex without any prefix, and then you can add the width and fill field. http://docs.python.org/2/library/stdtypes.html#str.format http://docs.python.org/2/library/string.html#formatstrings http://docs.python.org/2/library/string.html#format-specification-mini-language For starters, try: print 0x{0:02x}.format(12) or print 0x{0:02X}.format(12) if you like uppercase hex characters -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Python for IPSA (Power flow analysis)
On 05/28/2013 06:00 AM, Debbie wrote: Hi there, I am new to Python, Welcome. Could you tell us a little about yourself, such as whether you've experience in a few other languages, or if Python is your first programming experience? Also, what version of Python (presumably 2.7 or 2.6) and what OS ? and wondering if you could help me with python based coding for the IPSA (Power system analysis software). I have a electrical distribution network with generators, buses and loads, on which I am performing the load flow analysis every 1 hour for a period of 1 year. The code to perform instantaneous load/power flow analysis is given below. I need to modify it such that I can perform this load flow analysis every 1 hour for a period of 1 year. Please help. from ipsa import * I have no idea what functionality is in ipsa, so this whole message is a guess. First question is whether the ReadFile() below and the DoLoadFlow() read the whole year's data, or data for a particular hour. And if the latter, how do you get the next set of data? ipsasys = IscInterface() net = ipsasys.ReadFile(refinery.iif) bok = net.DoLoadFlow(); if bok: busbars = net.GetBusbars() print Load Flow results: print print BusName Vmag(kV) print for bus in busbars.itervalues(): name = bus.GetName() vm = bus.GetVoltageMagnitudekV() res = %-8s %10.5f % (name, vm) print res else: print Load Flow failed! Regards, Debbie First you want to make a function to print out a particular hour's data. That might turn out to be something like: def one_hour(net): busbars = net.GetBusbars() print Load Flow results: print print BusName Vmag(kV) print for bus in busbars.itervalues(): name = bus.GetName() vm = bus.GetVoltageMagnitudekV() res = %-8s %10.5f % (name, vm) print res (Just pasted from your code, I added in the probable parameter to the definition) Now your main function might be something like: def main(filename): ipsasys = IscInterface() net = ipsasys.ReadFile(filename) #if net gets you data for one hour, figure out how #to get the data for the whole year, in the form #of a list or an iterator called nets bok = net.DoLoadFlow(); if bok: for net in nets: one_hour(net) else: print Load Flow failed! #and your top-level code is: main(refinery.iif) As to ordering in the source file, put the import first: from ipsa import * then your function definitions one_hour() and main(), then your top-level code. -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Short-circuit Logic
On 28/05/2013 09:39, Ahmed Abdulshafy wrote: And that's not specific to Python. Using google products is also not specific to Python. However whereever it's used it's a PITA as people are forced into reading double spaced crap. Please check out the link in my signature. -- If you're using GoogleCrap™ please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence -- http://mail.python.org/mailman/listinfo/python-list
Re: Encodign issue in Python 3.3.1 (once again)
On May 28, 10:55 am, Νίκος Γκρ33κ nikos.gr...@gmail.com wrote: Ôç Ôñßôç, 28 ÌáÀïõ 2013 1:18:06 ð.ì. UTC+3, ï ÷ñÞóôçò Chris Angelico Ýãñáøå: You're effectively asking people to put in a few minutes' work, sometimes quite a few minutes, to help you. Is it too much to hope that you'll spend one more minute on your posts? No it is not, you are right, i should be more careful when typing and spend some time to correct before i send my responses. I promise i will not overlook this as well as the blank line google imposes. As fo my initial question any comments-remarks? You say you should be more careful to correct your typing and 'promise' to not overlook this. Your next line has a 'fo' instead of a 'for' -- http://mail.python.org/mailman/listinfo/python-list
Re: How to: Setuptools
On May 28, 6:32 am, ray r...@aarden.us wrote: I would like to use easy_install, but can't figure out how to install it. I have 64-bit Python 2.7.5 on Windows 7. Following the instructions onhttps://pypi.python.org/pypi/setuptools, it says: Download ez_setup.py and run it; it will download the appropriate .egg file and install it for you. (Currently, the provided .exe installer does not support 64-bit versions of Python for Windows, due to a distutils installer compatibility issue Being new to Python, I don't know what it means to run it. I am not sure what I am looking at when I open it as the first line is #!python. Looking down into the content of ez_setup.py, I find: 'setuptools-0.6c10-py2.6.egg': but there is no entry 'setuptools-0.6c10-py2.7.egg': Searching for it, I found a version at:https://pypi.python.org/packages/2.7/s/setuptools/ This appeared to be a linux version, the first line is: #!/bin/sh and the content seems to be encoded. There is an exe athttps://pypi.python.org/pypi/setuptools, but the instructions on the page state the .exe won't work for 64-bit installs. Ray Since there seems to be no response to this, let me try (even though I am not on windows) Just point your browser at the link http://peak.telecommunity.com/dist/ez_setup.py And save the file ez_setup.py The more windows-y way of running this is to right-click this and edit the run-with in some way that I dont have at my finger-tips. The more old-fashioned way is to start a dos-box (run cmd.exe) navigate to the directory where the ez_setup.py is saved from there run the command: python ez_setup.py Do that and report back on what happened -- http://mail.python.org/mailman/listinfo/python-list
Re: Python for IPSA (Power flow analysis)
On Tue, May 28 2013, Debbie dia.sus...@gmail.com wrote: Hi there, I am new to Python, and wondering if you could help me with python based coding for the IPSA (Power system analysis software). I have a electrical distribution network with generators, buses and loads, on which I am performing the load flow analysis every 1 hour for a period of 1 year. The code to perform instantaneous load/power flow analysis is given below. I need to modify it such that I can perform this load flow analysis every 1 hour for a period of 1 year. Please help. from ipsa import * ipsasys = IscInterface() net = ipsasys.ReadFile(refinery.iif) bok = net.DoLoadFlow(); if bok: busbars = net.GetBusbars() ... for bus in busbars.itervalues(): name = bus.GetName() .. else: print Load Flow failed! I think Dave's suggestions are useful, a few years ago I was one of the developers for the IPSA python API, I'm not sure how things have moved on since then but you need somewhere to incorporate some time modelling - at the moment I'm not sure how and if that was done. In any case I doubt if the simulation would give rigourous results over a simulation period of that length Is what you really have a set of iif files with current voltages over a set of periods within that year, if so you need to iterate though those, loading each one and doing individual load flows. IPSA has a linkedin discussion group and current IPSA developers will I think respond to you there (if you have an account) Robert -- La grenouille songe..dans son château d'eau Links and things http://rmstar.blogspot.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: How to: Setuptools
On 28/05/2013 13:03, rusi wrote: On May 28, 6:32 am, ray r...@aarden.us wrote: I would like to use easy_install, but can't figure out how to install it. I have 64-bit Python 2.7.5 on Windows 7. Following the instructions onhttps://pypi.python.org/pypi/setuptools, it says: Download ez_setup.py and run it; it will download the appropriate .egg file and install it for you. (Currently, the provided .exe installer does not support 64-bit versions of Python for Windows, due to a distutils installer compatibility issue Being new to Python, I don't know what it means to run it. I am not sure what I am looking at when I open it as the first line is #!python. Looking down into the content of ez_setup.py, I find: 'setuptools-0.6c10-py2.6.egg': but there is no entry 'setuptools-0.6c10-py2.7.egg': Searching for it, I found a version at:https://pypi.python.org/packages/2.7/s/setuptools/ This appeared to be a linux version, the first line is: #!/bin/sh and the content seems to be encoded. There is an exe athttps://pypi.python.org/pypi/setuptools, but the instructions on the page state the .exe won't work for 64-bit installs. Ray Since there seems to be no response to this, let me try (even though I am not on windows) Just point your browser at the link http://peak.telecommunity.com/dist/ez_setup.py And save the file ez_setup.py The more windows-y way of running this is to right-click this and edit the run-with in some way that I dont have at my finger-tips. Do this, something goes wrong, no output to see. The more old-fashioned way is to start a dos-box (run cmd.exe) navigate to the directory where the ez_setup.py is saved from there run the command: python ez_setup.py Do this, something goes wrong, output in front of you. Do that and report back on what happened -- If you're using GoogleCrap™ please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence -- http://mail.python.org/mailman/listinfo/python-list
Re: How to: Setuptools
On May 28, 7:26 am, Mark Lawrence breamore...@yahoo.co.uk wrote: On 28/05/2013 13:03, rusi wrote: On May 28, 6:32 am, ray r...@aarden.us wrote: I would like to use easy_install, but can't figure out how to install it. I have 64-bit Python 2.7.5 on Windows 7. Following the instructions onhttps://pypi.python.org/pypi/setuptools, it says: Download ez_setup.py and run it; it will download the appropriate .egg file and install it for you. (Currently, the provided .exe installer does not support 64-bit versions of Python for Windows, due to a distutils installer compatibility issue Being new to Python, I don't know what it means to run it. I am not sure what I am looking at when I open it as the first line is #!python. Looking down into the content of ez_setup.py, I find: 'setuptools-0.6c10-py2.6.egg': but there is no entry 'setuptools-0.6c10-py2.7.egg': Searching for it, I found a version at:https://pypi.python.org/packages/2.7/s/setuptools/ This appeared to be a linux version, the first line is: #!/bin/sh and the content seems to be encoded. There is an exe athttps://pypi.python.org/pypi/setuptools, but the instructions on the page state the .exe won't work for 64-bit installs. Ray Since there seems to be no response to this, let me try (even though I am not on windows) Just point your browser at the link http://peak.telecommunity.com/dist/ez_setup.py And save the file ez_setup.py The more windows-y way of running this is to right-click this and edit the run-with in some way that I dont have at my finger-tips. Do this, something goes wrong, no output to see. The more old-fashioned way is to start a dos-box (run cmd.exe) navigate to the directory where the ez_setup.py is saved from there run the command: python ez_setup.py Do this, something goes wrong, output in front of you. Do that and report back on what happened -- If you're using GoogleCrap� please read thishttp://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence The installation fails. The report stated it could not find the file. Per: Looking down into the content of ez_setup.py, I find: 'setuptools-0.6c10-py2.6.egg': but there is no entry 'setuptools-0.6c10-py2.7.egg': Since I am trying to install this for Python 2.7, it fails. Any suggestions? Ray -- http://mail.python.org/mailman/listinfo/python-list
Re: Python error codes and messages location
28.05.13 11:17, Chris Angelico написав(ла): On Tue, May 28, 2013 at 6:10 PM, Fábio Santos fabiosantos...@gmail.com wrote: Just to clarify, I am suggesting to have the unchanged messages in tracebacks, but having some methods in the exception to get the exception and message localised. Just like repr() and str() are directed at different audiences (the programmer vs. The user), so is a traceback vs a message box. There's no particular reason for that to be a method on the exception, then. You're just asking to localize a text string, and I think that functionality already exists someplace :) It will be very helpful in case of KeyError for example. -- http://mail.python.org/mailman/listinfo/python-list
Re: Source code as text/plain
Carlos Nepomuceno carlosnepomuc...@outlook.com writes: I'd like to have the option to download the source code as text/plain from the docs.python.org pages. For example: when I'm a docs page, such as: http://docs.python.org/2/library/string.html and I click the source code link I'm taken to a Mercurial page: http://hg.python.org/cpython/file/2.7/Lib/string.py but over there there's no way to get a clean text/plain version of the code because the line numbers are included. A link to the text/plain version on that page would be nice! The 'raw' link on the left spews the source as application/binary so most likely your browser will download it instead of showing it. Which is what you asked but if you wanted to view in browser sans the line numbers, there doesn't seem to be a way. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to: Setuptools
On May 28, 6:05 pm, ray r...@aarden.us wrote: On May 28, 7:26 am, Mark Lawrence breamore...@yahoo.co.uk wrote: On 28/05/2013 13:03, rusi wrote: On May 28, 6:32 am, ray r...@aarden.us wrote: I would like to use easy_install, but can't figure out how to install it. I have 64-bit Python 2.7.5 on Windows 7. Following the instructions onhttps://pypi.python.org/pypi/setuptools, it says: Download ez_setup.py and run it; it will download the appropriate .egg file and install it for you. (Currently, the provided .exe installer does not support 64-bit versions of Python for Windows, due to a distutils installer compatibility issue Being new to Python, I don't know what it means to run it. I am not sure what I am looking at when I open it as the first line is #!python. Looking down into the content of ez_setup.py, I find: 'setuptools-0.6c10-py2.6.egg': but there is no entry 'setuptools-0.6c10-py2.7.egg': Searching for it, I found a version at:https://pypi.python.org/packages/2.7/s/setuptools/ This appeared to be a linux version, the first line is: #!/bin/sh and the content seems to be encoded. There is an exe athttps://pypi.python.org/pypi/setuptools, but the instructions on the page state the .exe won't work for 64-bit installs. Ray Since there seems to be no response to this, let me try (even though I am not on windows) Just point your browser at the link http://peak.telecommunity.com/dist/ez_setup.py And save the file ez_setup.py The more windows-y way of running this is to right-click this and edit the run-with in some way that I dont have at my finger-tips. Do this, something goes wrong, no output to see. The more old-fashioned way is to start a dos-box (run cmd.exe) navigate to the directory where the ez_setup.py is saved from there run the command: python ez_setup.py Do this, something goes wrong, output in front of you. Do that and report back on what happened -- If you're using GoogleCrap� please read thishttp://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence The installation fails. The report stated it could not find the file. Per: Looking down into the content of ez_setup.py, I find: 'setuptools-0.6c10-py2.6.egg': but there is no entry 'setuptools-0.6c10-py2.7.egg': Since I am trying to install this for Python 2.7, it fails. Any suggestions? Ray Mysterious... If you are in hack mode you could try patching that file with the 2.7 egg name and md5 Both of them here https://pypi.python.org/pypi/setuptools ie after this line 'setuptools-0.6c11-py2.6.egg': 'bfa92100bd772d5a213eedd356d64086', add this line 'setuptools-0.6c11-py2.7.egg': 'fe1f997bc722265116870bc7919059ea', However it maybe a better idea to ask on the distutils mailing list http://mail.python.org/pipermail/distutils-sig/ [And let us know how/what happened!] -- http://mail.python.org/mailman/listinfo/python-list
Re: How to: Setuptools
On 28/05/2013 14:05, ray wrote: The installation fails. The report stated it could not find the file. Per: Looking down into the content of ez_setup.py, I find: 'setuptools-0.6c10-py2.6.egg': but there is no entry 'setuptools-0.6c10-py2.7.egg': Since I am trying to install this for Python 2.7, it fails. Any suggestions? Ray Try reading this http://stackoverflow.com/questions/3652625/installing-setuptools-on-64-bit-windows which refers to this http://www.lfd.uci.edu/~gohlke/pythonlibs/ where you can get pip which is an easy_install replacement. You pays your money, you takes your choice :) -- If you're using GoogleCrap™ please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence -- http://mail.python.org/mailman/listinfo/python-list
Re: Making safe file names
In article lvydneajg7lxnhtmnz2dnuvz_rkdn...@westnet.com.au, Neil Hodgson nhodg...@iinet.net.au wrote: Andrew Berg: This is not a Unicode issue since (modern) file systems will happily accept it. The issue is that certain characters (which are ASCII) are not allowed on some file systems: \ / : * ? | @ and the NUL character The first 9 are not allowed on NTFS, the @ is not allowed on ext3cow, and NUL and / are not allowed on pretty much any file system. Locale settings and encodings aside, these 11 characters will need to be escaped. There's also the Windows device name hole. There may be trouble with artists named 'COM4', 'CLOCK$', 'Con', or similar. http://support.microsoft.com/kb/74496 That applies to MS-DOS names. God forbid that this still holds on more modern Microsoft operating systems? http://en.wikipedia.org/wiki/Nul_%28band%29 Neil -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: Short-circuit Logic
On Mon, 27 May 2013 13:11:28 -0700, Ahmed Abdulshafy wrote: That may be true for integers, but for floats, testing for equality is not always precise Incorrect. Testing for equality is always precise, and exact. The problem is not the *equality test*, but that you don't always have the number that you think you have. The problem lies elsewhere, not equality! Unfortunately, people who say never test floats for equality have misdiagnosed the problem, or they are giving a simple work-around which can be misleading to those who don't understand what is actually going on. Any floating point libraries that support IEEE-754 semantics can guarantee a few things, including: x == 0.0 if, and only if, x actually equals zero. This was not always the case for all floating point systems prior to IEEE-754. In his forward to the Apple Numerics Manual, William Kahan describes a Capriciously Designed Computer where 1/x can give a Division By Zero error even though x != 0. Fortunately, if you are programming in Python on Intel-compatible hardware, you do not have to worry about nightmares like that. Let me repeat that: in Python, you can trust that if x == 0.0 returns False, then x is definitely not zero. In any case, the test that you show is not a good test. I have already shown that it wrongly treats many non-zero numbers which can be distinguished from zero as if they were zero. But worse, it also fails as a guard against numbers which cannot be distinguished from zero! py import sys py epsilon = sys.float_info.epsilon py x epsilon # Is x so tiny it looks like zero? False py y = 1e17 + x # x is not zero, so y should be 1e17 py 1/(1e17 - y) Traceback (most recent call last): File stdin, line 1, in module ZeroDivisionError: float division by zero So as you can see, testing for zero by comparing to machine epsilon does not save you from Zero Division errors. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Making safe file names
On Tue, May 28, 2013 at 11:44 PM, Albert van der Horst alb...@spenarnc.xs4all.nl wrote: In article lvydneajg7lxnhtmnz2dnuvz_rkdn...@westnet.com.au, Neil Hodgson nhodg...@iinet.net.au wrote: There's also the Windows device name hole. There may be trouble with artists named 'COM4', 'CLOCK$', 'Con', or similar. http://support.microsoft.com/kb/74496 That applies to MS-DOS names. God forbid that this still holds on more modern Microsoft operating systems? Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit (In tel)] on win32 Type help, copyright, credits or license for more information. open(com1,w).write(Test\n) Traceback (most recent call last): File stdin, line 1, in module FileNotFoundError: [Errno 2] No such file or directory: 'com1' open(con,w).write(Test\n) Test 5 ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: How to: Setuptools
On May 28, 6:40 pm, Mark Lawrence breamore...@yahoo.co.uk wrote: On 28/05/2013 14:05, ray wrote: The installation fails. The report stated it could not find the file. Per: Looking down into the content of ez_setup.py, I find: 'setuptools-0.6c10-py2.6.egg': but there is no entry 'setuptools-0.6c10-py2.7.egg': Since I am trying to install this for Python 2.7, it fails. Any suggestions? Ray Try reading thishttp://stackoverflow.com/questions/3652625/installing-setuptools-on-6... which refers to thishttp://www.lfd.uci.edu/~gohlke/pythonlibs/where you can get pip which is an easy_install replacement. You pays your money, you takes your choice :) Hmm... Something new (for me) Last I knew, pip was the supposed replacement for setuptools and you had to install setuptools to install pip!!! Maybe this has changed?? Or its different on windows?? -- http://mail.python.org/mailman/listinfo/python-list
Re: Short-circuit Logic
On Tue, 28 May 2013 01:39:09 -0700, Ahmed Abdulshafy wrote: He just said that the way to test for zero equality is x == 0, and I meant that this is true for integers but not necessarily for floats. And that's not specific to Python. Can you show me a value of x where x == 0.0 returns False, but x actually isn't zero? Built-in floats only, if you subclass you can do anything you like: class Cheating(float): def __eq__(self, other): return False -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Short-circuit Logic
On Tue, May 28, 2013 at 11:48 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: py y = 1e17 + x # x is not zero, so y should be 1e17 py 1/(1e17 - y) Traceback (most recent call last): File stdin, line 1, in module ZeroDivisionError: float division by zero You don't even need to go for 1e17. By definition: sys.float_info.epsilon+1.0==1.0 False sys.float_info.epsilon+2.0==2.0 True Therefore the same can be done with 2 as you did with 1e17. y = 2 + sys.float_info.epsilon 1/(2-y) Traceback (most recent call last): File pyshell#182, line 1, in module 1/(2-y) ZeroDivisionError: float division by zero Of course, since we're working with a number greater than epsilon, we need to go a little further, but we can still work with small numbers: x = sys.float_info.epsilon * 2 # Definitely greater than epsilon y = 4 + x 1/(4-y) Traceback (most recent call last): File pyshell#191, line 1, in module 1/(4-y) ZeroDivisionError: float division by zero ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Encodign issue in Python 3.3.1 (once again)
On 05/27/2013 02:17 PM, Νίκος Γκρ33κ wrote: I have checked the database through phpMyAdmin and it is indeed UTF-8. I have no idea why python 3.3.1 chooses to work with latin-iso only It's not python that is doing this here... If you look at the source code to pymysql, I'm sure you will identify the problem. In fact I'll even walk you through things. The traceback you posted tells you what's going on and why, with superfluous details removed for clarity: File /opt/python3/lib/python3.3/site-packages/pymysql/cursors.py, line 108, in execute: query = query.encode(charset) UnicodeEncodeError: 'latin-1' codec can't encode characters in position 46-52: ordinal not in range(256) So there we have it. pymysql is actually explicitly calling .encode() on a string and is using whatever character set is specified by the local variable charset. If you look in cursors.py at that line, and then a few lines above, you will find that charset is assigned to conn.charset. This means that the charset is actually defined in the connection object. So go look at connections.py. Sure enough, it shows that charset is defined by default as latin-1. That's no good for you. So take a look at the __init__ method in connections.py. In there you should find the necessary keyword argument you need to use when creating the mysql connection to make sure the charset is utf-8. -- http://mail.python.org/mailman/listinfo/python-list
Re: Reading *.json from URL - json.loads() versus urllib.urlopen.readlines()
Thanks to everyone for the help and insight. I think for now I'll just back away from this file and go back to something much easier to practice with. -- http://mail.python.org/mailman/listinfo/python-list
Re: Text-to-Sound or Vice Versa (Method NOT the source code)
On 2013-05-25, Rakshith Nayak rnyk1...@gmail.com wrote: Always wondered how sound is generated from text. Googling couldn't help. Devs having knowledge about this could provide, the information, Links, URLs or anything that could help. Helpful for those who want to dig to basics first before Coding http://www.cstr.ed.ac.uk/projects/festival/ http://code.google.com/p/pyfestival/ http://machakux.appspot.com/blog/44003/making_speech_with_python -- Grant Edwards grant.b.edwardsYow! at BI-BI-BI-BI-BI-BI gmail.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Short-circuit Logic
On 2013-05-28, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Tue, 28 May 2013 01:39:09 -0700, Ahmed Abdulshafy wrote: He just said that the way to test for zero equality is x == 0, and I meant that this is true for integers but not necessarily for floats. And that's not specific to Python. Can you show me a value of x where x == 0.0 returns False, but x actually isn't zero? I'm confused. Don't all non-zero values satisfy your conditions? x = 1.0 x == 0.0 False x is 0.0 False -- Grant Edwards grant.b.edwardsYow! I'm dressing up in at an ill-fitting IVY-LEAGUE gmail.comSUIT!! Too late... -- http://mail.python.org/mailman/listinfo/python-list
Re: Python error codes and messages location
On 28 May 2013 09:22, Chris Angelico ros...@gmail.com wrote: On Tue, May 28, 2013 at 6:10 PM, Fábio Santos fabiosantos...@gmail.com wrote: Just to clarify, I am suggesting to have the unchanged messages in tracebacks, but having some methods in the exception to get the exception and message localised. Just like repr() and str() are directed at different audiences (the programmer vs. The user), so is a traceback vs a message box. There's no particular reason for that to be a method on the exception, then. You're just asking to localize a text string, and I think that functionality already exists someplace :) Yes :) what we don't have is a translation string for every exception that Python could raise. Or at least some of them. OpenERP for example shows stack traces to the user. It could show a shorter message in the user's language. Sounds like an OpenERP feature request, then. No, it's just something that OpenERP would obviously do if it had a library to, or language support :) this could be the One Obvious Way To Do It for displaying error messages in localised applications. That said, I'm going to think about this and maybe write a library for localising exceptions and a portuguese translation pack. PS. FWIW I'm rather stubborn sometimes. Sorry if I bothered you in any way. -- http://mail.python.org/mailman/listinfo/python-list
IndentationError: expected an indented block but it's there
Having a problem getting a py script to execute. Got this error: File /scripts/blockIPv4.py, line 19 ip = line.split(';')[0] ^ IndentationError: expected an indented block I'm perplexed because the code that the error refers to *is* indented: with open('/var/www/html/mydomain.com/banlist.txt','r') as inFile: for line in inFile.readlines(): ip = line.split(';')[0] output = os.popen( '/etc/sysconfig/iptables -A INPUT -s ' + ip + ' -j REJECT' ) logFile.write(ip+' - Has been blocked\n') What am I missing here? -- My email address on the header is a non-monitored spam catching account. I can be reached via http://www.wvnh.net/contact.htm -- http://mail.python.org/mailman/listinfo/python-list
Re: Output from to_bytes
On 2013-05-26, Mok-Kong Shen mok-kong.s...@t-online.de wrote: I don't understand why with the code: for k in range(8,12,1): print(k.to_bytes(2,byteorder='big')) one gets the following output: b'\x00\x08' b'\x00\t' b'\x00\n' b'\x00\x0b' I mean the 2nd and 3rd should be b'\x00\x09' and b'x00\x0a'. Anyway, how could I get the output in the forms I want? Well, it would help if you told us what output form you want. -- Grant Edwards grant.b.edwardsYow! I'm gliding over a at NUCLEAR WASTE DUMP near gmail.comATLANTA, Georgia!! -- http://mail.python.org/mailman/listinfo/python-list
Re: Future standard GUI library
On 2013-05-26, Roy Smith r...@panix.com wrote: Michael Torrie torr...@gmail.com wrote: On good thing web development has brought us is the knowledge that modularization and layers are a brilliant idea. Modularization and layers were a brilliant idea long before the web came around. Once again USENET proves to be an unsuitable RPC protocol for implementing irony. :) [OTOH, perhaps Micheal wasn't being ironic...] -- Grant Edwards grant.b.edwardsYow! Am I having fun yet? at gmail.com -- http://mail.python.org/mailman/listinfo/python-list
Re: IndentationError: expected an indented block but it's there
On 05/28/2013 09:32 AM, JackM wrote: Having a problem getting a py script to execute. Got this error: File /scripts/blockIPv4.py, line 19 ip = line.split(';')[0] ^ IndentationError: expected an indented block I'm perplexed because the code that the error refers to *is* indented: with open('/var/www/html/mydomain.com/banlist.txt','r') as inFile: for line in inFile.readlines(): ip = line.split(';')[0] output = os.popen( '/etc/sysconfig/iptables -A INPUT -s ' + ip + ' -j REJECT' ) logFile.write(ip+' - Has been blocked\n') What am I missing here? Indentation has to be consistent. likely the for line is indented with spaces and the next line with a tab. You can use tabs and spaces, but you have to be consistent with how you use them. IE if level 1 is indented with spaces, then level 2 has to be indented with spaces up to level 1 as well. Hope that makes sense. -- http://mail.python.org/mailman/listinfo/python-list
Re: Short-circuit Logic
On Tue, 28 May 2013 15:14:03 +, Grant Edwards wrote: On 2013-05-28, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Tue, 28 May 2013 01:39:09 -0700, Ahmed Abdulshafy wrote: He just said that the way to test for zero equality is x == 0, and I meant that this is true for integers but not necessarily for floats. And that's not specific to Python. Can you show me a value of x where x == 0.0 returns False, but x actually isn't zero? I'm confused. Don't all non-zero values satisfy your conditions? Of course they do :-( I meant but x actually *is* zero. Sorry for the confusion. I blame the terrists. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: IndentationError: expected an indented block but it's there
On Tue, 28 May 2013 11:32:06 -0400, JackM wrote: Having a problem getting a py script to execute. Got this error: File /scripts/blockIPv4.py, line 19 ip = line.split(';')[0] ^ IndentationError: expected an indented block I'm perplexed because the code that the error refers to *is* indented: Whenever you get perplexing indentation errors, suspect an inconsistency due to mixed tabs and spaces. Tabs good. Spaces good. Tabs and spaces together, bad. You can run the tabnanny module over your source code: python -m tabnanny file-or-directory to convert indentation to all spaces. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: how to compare two json file line by line using python?
On 2013-05-27, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Sun, 26 May 2013 21:32:40 -0700, Avnesh Shakya wrote: But I want to compare line by line and value by value. but i found that json data is unordered data, so how can i compare them without sorting it. please give me some idea about it. I am new for it. I want to check every value line by line. Why do you care about checking every value line by line? As you say yourself, JSON data is unordered, so line by line is the wrong way to compare it. There's no such thing as lines in JSON anyway. Outside of string literals, all whitespace is equivalent, so replacing all newlines with space characters results in equivalent blobs of JSON -- but one is a single line, and the other is multiple lines. The right way is to decode the JSON data, and then compare whether it gives you the result you expect: a = json.load(file-a) b = json.load(file-b) if a == b: print(file-a and file-b contain the same JSON data) If what you care about is the *data* stored in the JSON file, this is the correct way to check it. Yup. -- Grant Edwards grant.b.edwardsYow! Are we laid back yet? at gmail.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Making safe file names
On 2013-05-28, Albert van der Horst alb...@spenarnc.xs4all.nl wrote: There's also the Windows device name hole. There may be trouble with artists named 'COM4', 'CLOCK$', 'Con', or similar. http://support.microsoft.com/kb/74496 That applies to MS-DOS names. God forbid that this still holds on more modern Microsoft operating systems? There are no more modern Microsoft operating systems. Only more recent ones. There are still lots of reserved filenames in recent versions of Windows. -- Grant Edwards grant.b.edwardsYow! I've got an IDEA!! at Why don't I STARE at you gmail.comso HARD, you forget your SOCIAL SECURITY NUMBER!! -- http://mail.python.org/mailman/listinfo/python-list
Re: Encodign issue in Python 3.3.1 (once again)
I do not know here to find connections.py Michael. But i do not understand since iam suing the following 2 statements, why a unicode error remains. #needed line, script does *not* work without it sys.stdout = os.fdopen(1, 'w', encoding='utf-8') # connect to database con = pymysql.connect( db = 'pelatologio', host = 'localhost', user = 'myself', passwd = 'mypass', init_command='SET NAMES UTF8' ) cur = con.cursor() Shall i chnage the connector form 'pymysql' = 'MySQLdb' ? -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get an integer from a sequence of bytes
On 2013-05-27, Mok-Kong Shen mok-kong.s...@t-online.de wrote: From an int one can use to_bytes to get its individual bytes, but how can one reconstruct the int from the sequence of bytes? One way is using the struct module. -- Grant Edwards grant.b.edwardsYow! Uh-oh!! I forgot at to submit to COMPULSORY gmail.comURINALYSIS! -- http://mail.python.org/mailman/listinfo/python-list
Re: IndentationError: expected an indented block but it's there
JackM wrote: Having a problem getting a py script to execute. Got this error: File /scripts/blockIPv4.py, line 19 ip = line.split(';')[0] ^ IndentationError: expected an indented block I'm perplexed because the code that the error refers to *is* indented: with open('/var/www/html/mydomain.com/banlist.txt','r') as inFile: for line in inFile.readlines(): ip = line.split(';')[0] output = os.popen( '/etc/sysconfig/iptables -A INPUT -s ' + ip + ' -j REJECT' ) logFile.write(ip+' - Has been blocked\n') What am I missing here? If you are mixing tabs and spaces to indent your code and have your editor configured with a tab width other than eight your code may look correct when it isn't. A simulation in the interactive interpreter: The actual file contents: s = if 1:\n\tif 2:\n\tprint 'hi' What you see: print s.expandtabs(4) if 1: if 2: print 'hi' exec s.expandtabs(4) hi What Python sees: print s.expandtabs(8) if 1: if 2: print 'hi' exec s Traceback (most recent call last): File stdin, line 1, in module File string, line 3 print 'hi' ^ IndentationError: expected an indented block Solution: configure your editor to use four spaces for indentation. -- http://mail.python.org/mailman/listinfo/python-list
Re: Encodign issue in Python 3.3.1 (once again)
On 28/05/2013 17:00, Νίκος Γκρ33κ wrote: I do not know here to find connections.py Michael. But i do not understand since iam suing the following 2 statements, why a unicode error remains. #needed line, script does *not* work without it sys.stdout = os.fdopen(1, 'w', encoding='utf-8') # connect to database con = pymysql.connect( db = 'pelatologio', host = 'localhost', user = 'myself', passwd = 'mypass', init_command='SET NAMES UTF8' ) cur = con.cursor() Shall i chnage the connector form 'pymysql' = 'MySQLdb' ? A quick look at the documentation tells me that the charset can be specified in the 'connect' call, something like this: con = pymysql.connect( db = 'pelatologio', host = 'localhost', user = 'myself', passwd = 'mypass', init_command='SET NAMES UTF8', charset = 'utf-8' ) -- http://mail.python.org/mailman/listinfo/python-list
Re: IndentationError: expected an indented block but it's there
On Wed, May 29, 2013 at 2:19 AM, Peter Otten __pete...@web.de wrote: Solution: configure your editor to use four spaces for indentation. ITYM eight spaces. But the real solution is to not mix tabs and spaces. Stick to one or the other and you're safe. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Encodign issue in Python 3.3.1 (once again)
On 05/28/2013 10:00 AM, Νίκος Γκρ33κ wrote: I do not know here to find connections.py Michael. It's part of the pymysql package that you installed. Look in there (the traceback even shows you where the file is). But you actually don't even need to look at it on your server. You can see the source code for it here: https://github.com/petehunt/PyMySQL/tree/master/pymysql But i do not understand since iam suing the following 2 statements, why a unicode error remains. The traceback told you why the error is happening. inside the pymysql library, there is a call to .encode(charset) on your query string. And the default charset is latin-1. You've got to work out a way to change that and I've already told you exactly how to find out what you need to do. #needed line, script does *not* work without it sys.stdout = os.fdopen(1, 'w', encoding='utf-8') # connect to database con = pymysql.connect( db = 'pelatologio', host = 'localhost', user = 'myself', passwd = 'mypass', init_command='SET NAMES UTF8' ) cur = con.cursor() HINT: this line ^^ is what you have to modify by passing in a particular keyword argument that sets the character set (no it's not the init_command one). You will have to look at connections.py's __init__ declaration and you should see what you need to pass in. Yes I could have saved myself a lot of time and typing by giving you the answer, but that isn't going to help you. On the other hand, if you want the easy way out, paypal some money to me and I'll just give you the answer instead of trying to give you the tools you need to debug this issue. The answers are all in the source code to pymysql, which is open source so you can always read (either on your own server file system or on the git repository). Shall i chnage the connector form 'pymysql' = 'MySQLdb' ? No. -- http://mail.python.org/mailman/listinfo/python-list
Re: Encodign issue in Python 3.3.1 (once again)
con = pymysql.connect( db = 'pelatologio', host = 'localhost', user = 'blabla', passwd = 'blabla', init_command='SET NAMES UTF8', charset = 'utf-8' ) produces this God knows what error traceback /home/nikos/public_html/cgi-bin/metrites.py in () 217 template = htmldata + counter 218 elif page.endswith('.py'): = 219 htmldata = subprocess.check_output( '/home/nikos/public_html/cgi-bin/' + page ) 220 template = htmldata.decode('utf-8').replace( 'Content-type: text/html; charset=utf-8', '' ) + counter 221 htmldata undefined, subprocess = module 'subprocess' from '/opt/python3/lib/python3.3/subprocess.py', subprocess.check_output = function check_output, page = 'pelatologio.py' /opt/python3/lib/python3.3/subprocess.py in check_output(timeout=None, *popenargs=('/home/nikos/public_html/cgi-bin/pelatologio.py',), **kwargs={}) 584 retcode = process.poll() 585 if retcode: = 586 raise CalledProcessError(retcode, process.args, output=output) 587 return output 588 global CalledProcessError = class 'subprocess.CalledProcessError', retcode = 1, process = subprocess.Popen object, process.args = '/home/nikos/public_html/cgi-bin/pelatologio.py', output = b'!--: spam\nContent-Type: text/html\n\nbody b...Type\' object has no attribute \'id\'\n\n--\n\n' CalledProcessError: Command '/home/nikos/public_html/cgi-bin/pelatologio.py' returned non-zero exit status 1 args = (1, '/home/nikos/public_html/cgi-bin/pelatologio.py') cmd = '/home/nikos/public_html/cgi-bin/pelatologio.py' output = b'!--: spam\nContent-Type: text/html\n\nbody b...Type\' object has no attribute \'id\'\n\n--\n\n' returncode = 1 with_traceback = built-in method with_traceback of CalledProcessError object -- http://mail.python.org/mailman/listinfo/python-list
Re: IndentationError: expected an indented block but it's there
Chris Angelico wrote: On Wed, May 29, 2013 at 2:19 AM, Peter Otten __pete...@web.de wrote: Solution: configure your editor to use four spaces for indentation. ITYM eight spaces. I meant: one hit of the Tab key should add spaces up to the next multiple of four. Which implies But the real solution is to not mix tabs and spaces. Stick to one or the other and you're safe. -- http://mail.python.org/mailman/listinfo/python-list
Re: Encodign issue in Python 3.3.1 (once again)
On 05/28/2013 10:45 AM, Νίκος Γκρ33κ wrote: con = pymysql.connect( db = 'pelatologio', host = 'localhost', user = 'blabla', passwd = 'blabla', init_command='SET NAMES UTF8', charset = 'utf-8' ) produces this God knows what error traceback Hey at least your database code is now working. /home/nikos/public_html/cgi-bin/metrites.py in () 217 template = htmldata + counter 218 elif page.endswith('.py'): = 219 htmldata = subprocess.check_output( '/home/nikos/public_html/cgi-bin/' + page ) 220 template = htmldata.decode('utf-8').replace( 'Content-type: text/html; charset=utf-8', '' ) + counter 221 htmldata undefined, subprocess = module 'subprocess' from '/opt/python3/lib/python3.3/subprocess.py', subprocess.check_output = function check_output, page = 'pelatologio.py' /opt/python3/lib/python3.3/subprocess.py in check_output(timeout=None, *popenargs=('/home/nikos/public_html/cgi-bin/pelatologio.py',), **kwargs={}) 584 retcode = process.poll() 585 if retcode: = 586 raise CalledProcessError(retcode, process.args, output=output) 587 return output 588 global CalledProcessError = class 'subprocess.CalledProcessError', retcode = 1, process = subprocess.Popen object, process.args = '/home/nikos/public_html/cgi-bin/pelatologio.py', output = b'!--: spam\nContent-Type: text/html\n\nbody b...Type\' object has no attribute \'id\'\n\n--\n\n' CalledProcessError: Command '/home/nikos/public_html/cgi-bin/pelatologio.py' returned non-zero exit status 1 args = (1, '/home/nikos/public_html/cgi-bin/pelatologio.py') cmd = '/home/nikos/public_html/cgi-bin/pelatologio.py' output = b'!--: spam\nContent-Type: text/html\n\nbody b...Type\' object has no attribute \'id\'\n\n--\n\n' returncode = 1 with_traceback = built-in method with_traceback of CalledProcessError object Again the traceback is telling you where to look for the problem. And the problem is in your own script, pelatologio.py, though the line number that's causing the problem is obscured. Basically you want pelatologio.py to run and then you process the output through a template, correct? Well the traceback is telling you that pelatologio.py is erroring out. In fact, subprocess is telling you that this process (your script) quit with an error. Though the line number in pelatologio.py is unknown (the traceback is obscured by your html processing code in your template processor), the error message itself is not. Inside pelatologio.py there is some object that you are trying to reference the id attribute on it does not contain id. So the problem is in pelatologio.py. Double check your code there. Try to make a standalone test file you can run locally. -- http://mail.python.org/mailman/listinfo/python-list
usage of os.posix_fadvise
Dear all, I was just experimenting for the first time with os.posix_fadvise(), which is new in Python3.3 . I'm reading from a really huge file (several GB) and I want to use the data only once, so I don't want OS-level page caching. I tried os.posix_fadvise with the os.POSIX_FADV_NOREUSE and with the os.POSIX_FADV_DONTNEED flags, but neither seemed to have any effect on the caching behaviour of Ubuntu (still uses all available memory to page cache my I/O). Specifically, I was trying this: import os fd = os.open('myfile', os.O_RDONLY) # wasn't sure about the len parameter in fadvise, # so thought I just use it on the first 4GB os.posix_fadvise(fd, 0, 40, os.POSIX_FADV_NOREUSE) # or DONTNEED then reading from the file with os.read() . By its very nature, I suppose posix_fadvise's effects will be OS-dependent, so my question is whether the lack of effect I'm observing is something Ubuntu-specific, or if I'm just using it in a wrong way. Any help is greatly appreciated! Best, Wolfgang -- http://mail.python.org/mailman/listinfo/python-list
Re: Future standard GUI library
Please give me an example of a suitable transport layer for a RPC protocol. I won't give you an example, but just some very basic criteria: - It must be very efficient for very small datagrams - It must provide connections - For asynchronous programming it must provide for callbacks No RPC-over-HTTP protocol that I know of does this. Besides, no one needs RPC just to logically separate GUI and application layer. And between application logic and database, you use the native database API for the RDBMS in question, of course. The whole idea to centralise application logic (and even the GUI with web applications) is backwards, it dates from the 70s/early 80s when desktop computers weren't able to run application logic. Today, to make an application responsive (minimise latencies and maximise throughput), it's just obvious to *de*-centralise as much as possible. In fact, if Postgres-R was available for production, you could even distribute the persistence and run an entirely serverless application. Sincerely, Wolfgang -- http://mail.python.org/mailman/listinfo/python-list
Re: Future standard GUI library
What is screenwork? Actually productive work of significant intensity at a computer screen. As opposed to leisurely clicking around like managers, administrators or home users (gaming, webbing,...) do. Sincerely, Wolfgang -- http://mail.python.org/mailman/listinfo/python-list
Re: Reading *.json from URL - json.loads() versus urllib.urlopen.readlines()
On Tue, 28 May 2013 08:31:35 +0100, Fábio Santos wrote: On 28 May 2013 04:19, Bryan Britten britten.br...@gmail.com wrote: I'm not familiar with using read(4096), I'll have to look into that. When I tried to just save the file, my computer just sat in limbo for some time and didn't seem to want to process the command. That's just file.read with an integer argument. You can read a file by chunks by repeatedly calling that function until you get the empty string. Based on my *extremely* limited knowledge of JSON, that's definitely the type of file this is. Here is a snippet of what is seen when you log in: ... That's json. It's pretty big, but not big enough to stall a slow computer more than half a second. - I've looked for documentation on that method on twitter. It seems that it's part of the twitter streaming api. https://dev.twitter.com/docs/streaming-apis What this means is that the requests aren't supposed to end. They are supposed to be read gradually, using the lines to split the response into meaningful chunks. That's why you can't read the data and why your browser never gets around to download it. Both urlopen and your browser block while waiting for the request to end. Are we overlooking the obvious why not use one of the Python twitter modules to isolate your app from the nitty-gritty details of the twitter stream https://dev.twitter.com/docs/twitter-libraries -- Given sufficient time, what you put off doing today will get done by itself. -- http://mail.python.org/mailman/listinfo/python-list
ANN: python-ldap 2.4.11
Find a new release of python-ldap: http://pypi.python.org/pypi/python-ldap/2.4.11 python-ldap provides an object-oriented API to access LDAP directory servers from Python programs. It mainly wraps the OpenLDAP 2.x libs for that purpose. Additionally it contains modules for other LDAP-related stuff (e.g. processing LDIF, LDAP URLs and LDAPv3 schema). Project's web site: http://www.python-ldap.org/ Ciao, Michael. Released 2.4.11 2013-05-27 Changes since 2.4.10: Lib/ * ldap.controls.DecodeControlTuples() now simply ignores PyAsn1Error exception raised during decoding malformed response control values in case of non-critical controls. * ldif.LDIFWriter.unparse() does not simply skip empty records anymore. -- http://mail.python.org/mailman/listinfo/python-list
Re: Encodign issue in Python 3.3.1 (once again)
On Tue, May 28, 2013 at 2:08 PM, nagia.rets...@gmail.com wrote: Τη Τρίτη, 28 Μαΐου 2013 8:17:05 μ.μ. UTC+3, ο χρήστης Michael Torrie έγραψε: Basically you want pelatologio.py to run and then you process the output through a template, correct? That is correct. Inside pelatologio.py there is some object that you are trying to reference the id attribute on it does not contain id. So the problem is in pelatologio.py. Double check your code there. Try to make a standalone test file you can run locally. I have, i see no error, the error appears only when i append the charset directive into the connector, if i remove it the error dissapears. -- http://mail.python.org/mailman/listinfo/python-list http://en.wikipedia.org/wiki/Dunning%E2%80%93Kruger_effect Could this be the problem? ;) -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Future standard GUI library
On 05/28/2013 11:26 AM, Wolfgang Keller wrote: Please give me an example of a suitable transport layer for a RPC protocol. I won't give you an example, but just some very basic criteria: - It must be very efficient for very small datagrams I won't argue for XML here, but sometimes space efficiency is simply a premature optimization. - It must provide connections How would you do this? Connections can and do get dropped regularly. To rebuild connections you need another layer to track them. - For asynchronous programming it must provide for callbacks What do you mean by this? A transport layer has nothing to do with callbacks. All a client can do is make the call, and wait for the answer. The client library can make it look asynchronous of course. And I suppose one could implement an RPC system using UDP where answer packets are dispatched as they come in. -- http://mail.python.org/mailman/listinfo/python-list
Re: Encodign issue in Python 3.3.1 (once again)
Τη Τρίτη, 28 Μαΐου 2013 8:17:05 μ.μ. UTC+3, ο χρήστης Michael Torrie έγραψε: Basically you want pelatologio.py to run and then you process the output through a template, correct? That is correct. Inside pelatologio.py there is some object that you are trying to reference the id attribute on it does not contain id. So the problem is in pelatologio.py. Double check your code there. Try to make a standalone test file you can run locally. I have, i see no error, the error appears only when i append the charset directive into the connector, if i remove it the error dissapears. -- http://mail.python.org/mailman/listinfo/python-list
Re: Encodign issue in Python 3.3.1 (once again)
On 05/28/2013 12:08 PM, nagia.rets...@gmail.com wrote: Τη Τρίτη, 28 Μαΐου 2013 8:17:05 μ.μ. UTC+3, ο χρήστης Michael Torrie έγραψε: Basically you want pelatologio.py to run and then you process the output through a template, correct? That is correct. Inside pelatologio.py there is some object that you are trying to reference the id attribute on it does not contain id. So the problem is in pelatologio.py. Double check your code there. Try to make a standalone test file you can run locally. I have, i see no error, the error appears only when i append the charset directive into the connector, if i remove it the error dissapears. No, when you remove the charset directive your database call fails and thus things fail even earlier. -- http://mail.python.org/mailman/listinfo/python-list
Re: Future standard GUI library
On 2013-05-28, Wolfgang Keller felip...@gmx.net wrote: Actually productive work of significant intensity at a computer screen. Oh. You mean emacs. -- Grant Edwards grant.b.edwardsYow! Will it improve my at CASH FLOW? gmail.com -- http://mail.python.org/mailman/listinfo/python-list
String object has no attribute append
I receive this error while toying around with Functions... def pulldata(speclist,speccolumn): with open('profiles.csv', 'r') as f: reader = csv.reader(f) for column in reader: (speclist).append(column[('speccolumn')]) pulldata(speclist = 'numbers', speccolumn = 0) Traceback (most recent call last): File C:\Desktop\Python\CFI\Devices V2\users.py, line 17, in module pulldata(speclist = 'numbers', speccolumn = 0) File C:\Desktop\Python\CFI\Devices V2\users.py, line 16, in pulldata (speclist).append(column[('speccolumn')]) AttributeError: 'str' object has no attribute 'append' I'm getting the error because it should say numbers.append, but it is reading it as (speclist).append. This is my first time playing with functions, so be gentle. -- http://mail.python.org/mailman/listinfo/python-list
Re: String object has no attribute append
On Tue, May 28, 2013, at 02:25 PM, Matt Graves wrote: I receive this error while toying around with Functions... def pulldata(speclist,speccolumn): with open('profiles.csv', 'r') as f: reader = csv.reader(f) for column in reader: (speclist).append(column[('speccolumn')]) pulldata(speclist = 'numbers', speccolumn = 0) Traceback (most recent call last): File C:\Desktop\Python\CFI\Devices V2\users.py, line 17, in module pulldata(speclist = 'numbers', speccolumn = 0) File C:\Desktop\Python\CFI\Devices V2\users.py, line 16, in pulldata (speclist).append(column[('speccolumn')]) AttributeError: 'str' object has no attribute 'append' I'm getting the error because it should say numbers.append, but it is reading it as (speclist).append. Because it indeed says (speclist).append... am I missing something? -- http://mail.python.org/mailman/listinfo/python-list
Re: String object has no attribute append
On Tue, May 28, 2013 at 12:25 PM, Matt Graves tunacu...@gmail.com wrote: I receive this error while toying around with Functions... def pulldata(speclist,speccolumn): with open('profiles.csv', 'r') as f: reader = csv.reader(f) for column in reader: (speclist).append(column[('speccolumn')]) pulldata(speclist = 'numbers', speccolumn = 0) Traceback (most recent call last): File C:\Desktop\Python\CFI\Devices V2\users.py, line 17, in module pulldata(speclist = 'numbers', speccolumn = 0) File C:\Desktop\Python\CFI\Devices V2\users.py, line 16, in pulldata (speclist).append(column[('speccolumn')]) AttributeError: 'str' object has no attribute 'append' I'm getting the error because it should say numbers.append, but it is reading it as (speclist).append. This is my first time playing with functions, so be gentle. It looks like you're trying to pass in a list called 'numbers' into the pulldata function, but that is not what's happening. Because of the single quotes you have around numbers, you are passing in the /string/ 'numbers' and calling it 'speclist' instead. The same goes for speccolumn as well; I think you mean to pass in the integer 0, but you're passing in the string 0 instead. Try it without the quotes: pulldata(speclist = numbers, speccolumn = 0) -- http://mail.python.org/mailman/listinfo/python-list
Re: String object has no attribute append
On Tue, May 28, 2013 at 12:41 PM, Ian Kelly ian.g.ke...@gmail.com wrote: On Tue, May 28, 2013 at 12:25 PM, Matt Graves tunacu...@gmail.com wrote: I receive this error while toying around with Functions... def pulldata(speclist,speccolumn): with open('profiles.csv', 'r') as f: reader = csv.reader(f) for column in reader: (speclist).append(column[('speccolumn')]) pulldata(speclist = 'numbers', speccolumn = 0) Traceback (most recent call last): File C:\Desktop\Python\CFI\Devices V2\users.py, line 17, in module pulldata(speclist = 'numbers', speccolumn = 0) File C:\Desktop\Python\CFI\Devices V2\users.py, line 16, in pulldata (speclist).append(column[('speccolumn')]) AttributeError: 'str' object has no attribute 'append' I'm getting the error because it should say numbers.append, but it is reading it as (speclist).append. This is my first time playing with functions, so be gentle. It looks like you're trying to pass in a list called 'numbers' into the pulldata function, but that is not what's happening. Because of the single quotes you have around numbers, you are passing in the /string/ 'numbers' and calling it 'speclist' instead. The same goes for speccolumn as well; I think you mean to pass in the integer 0, but you're passing in the string 0 instead. Try it without the quotes: pulldata(speclist = numbers, speccolumn = 0) And along the same lines, the expression column[('speccolumn')] should just be column[speccolumn]. -- http://mail.python.org/mailman/listinfo/python-list
Re: Encodign issue in Python 3.3.1 (once again)
Τη Τρίτη, 28 Μαΐου 2013 9:19:21 μ.μ. UTC+3, ο χρήστης Michael Torrie έγραψε: On 05/28/2013 12:08 PM, nagia.rets...@gmail.com wrote: Τη Τρίτη, 28 Μαΐου 2013 8:17:05 μ.μ. UTC+3, ο χρήστης Michael Torrie έγραψε: Basically you want pelatologio.py to run and then you process the output through a template, correct? That is correct. Inside pelatologio.py there is some object that you are trying to reference the id attribute on it does not contain id. So the problem is in pelatologio.py. Double check your code there. Try to make a standalone test file you can run locally. I have, i see no error, the error appears only when i append the charset directive into the connector, if i remove it the error dissapears. No, when you remove the charset directive your database call fails and thus things fail even earlier. Yes, it does create issues. i just tried to add it to metrites.py for testing and it breaks too. https://github.com/petehunt/PyMySQL/issues/38 Switching back to MySQLdb. -- http://mail.python.org/mailman/listinfo/python-list
Python #ifdef
Are there Python 'preprocessor directives'? I'd like to have something like '#ifdef' to mix code from Python 2 and 3 in a single file. Is that possible? How? -- http://mail.python.org/mailman/listinfo/python-list
Re: Encodign issue in Python 3.3.1 (once again)
But i think iam gonna fight it some more because mysqldb in python 3 has issues too :( -- http://mail.python.org/mailman/listinfo/python-list
Re: Python #ifdef
No On May 28, 2013 3:48 PM, Carlos Nepomuceno carlosnepomuc...@outlook.com wrote: Are there Python 'preprocessor directives'? I'd like to have something like '#ifdef' to mix code from Python 2 and 3 in a single file. Is that possible? How? -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Python #ifdef
On 05/28/2013 03:46 PM, Carlos Nepomuceno wrote: Are there Python 'preprocessor directives'? Python doesn't define a preprocessor, and CPYthon doesn't implement one. Nothing to stop you from doing so, however. I'd like to have something like '#ifdef' to mix code from Python 2 and 3 in a single file. Is that possible? How? It's quite possible that you don't need a preprocessor do what you want, since Python does much less compile-time checking than C. Also, it's possible to store function objects and module objects in variables, and thus to hide many things from the body of the code. One biggie is print, since that's a reserved word (and a statement) in Python 2.x. But if you're using 2.7 you can use from __future__ import print, or something like that, and just use 3.x function semantics. -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Python #ifdef
On 2013-05-28, Joel Goldstick joel.goldst...@gmail.com wrote: No Yes. More below. On May 28, 2013 3:48 PM, Carlos Nepomuceno carlosnepomuc...@outlook.com wrote: Are there Python 'preprocessor directives'? I'd like to have something like '#ifdef' to mix code from Python 2 and 3 in a single file. Is that possible? How? You need sys.version_info. For more, see http://python3porting.com/noconv.html -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list
RE: Python #ifdef
Thank you! I made it run like the following. What do you think about that? IS there a better way? #The following runs on Python 2.7 sc3=''' # Python 3 def original(n): m = 0 for b in n.to_bytes(6, 'big'): m = 256*m + b return m ''' if sys.version_info[0] == 3: exec(sc3) -- http://mail.python.org/mailman/listinfo/python-list
Re: Python #ifdef
On 2013-05-28, Carlos Nepomuceno carlosnepomuc...@outlook.com wrote: Thank you! I made it run like the following. What do you think about that? IS there a better way? #The following runs on Python 2.7 sc3=''' # Python 3 def original(n): ??? m = 0 ??? for b in n.to_bytes(6, 'big'): ??? m = 256*m + b ??? return m ''' if sys.version_info[0] == 3: ??? exec(sc3) You're trying to make this a lot harder than it really is: if sys.version_info[0] == 3: def original(n): m = 0 for b in n.to_bytes(6, 'big'): m = 256*m + b return m else: def original(n): something else? -- Grant Edwards grant.b.edwardsYow! Am I having fun yet? at gmail.com -- http://mail.python.org/mailman/listinfo/python-list
RE: Python #ifdef
On May 28, 2013 1:10 PM, Carlos Nepomuceno carlosnepomuc...@outlook.com wrote: Thank you! I made it run like the following. What do you think about that? IS there a better way? #The following runs on Python 2.7 sc3=''' # Python 3 def original(n): m = 0 for b in n.to_bytes(6, 'big'): m = 256*m + b return m ''' if sys.version_info[0] == 3: exec(sc3) -- No need for exec. if sys.version_info[0] = 3: def original(n) : ... -- http://mail.python.org/mailman/listinfo/python-list
RE: Python #ifdef
From: invalid@invalid.invalid Subject: Re: Python #ifdef [...] You're trying to make this a lot harder than it really is: if sys.version_info[0] == 3: def original(n): m = 0 for b in n.to_bytes(6, 'big'): m = 256*m + b return m else: def original(n): something else? -- Grant Edwards grant.b.edwards Yow! Am I having fun yet? at gmail.com Haha! That's it!!! Just realized how funny this can be: ;) ### never to be opened ### def pandoras_box(v): return v/0.0 if customer_didnt_pay(): pandoras_box() #lol -- http://mail.python.org/mailman/listinfo/python-list
PyDev 2.7.5 Released
Hi All, PyDev 2.7.5 has been released Details on PyDev: http://pydev.org Details on its development: http://pydev.blogspot.com Release Highlights: --- * Icons in the outline are now correct. * Fixed deadlock found on code analysis. * Project-related error markers no longer created in the main thread. * Showing a dialog to select template when a new module is created. * PyUnit view output font uses the same font as the console * New option in auto-formatting to auto-format only workspace files. * Auto-formatting with only deleted lines no longer changes everything. * PyUnit view orientation menu is now properly shown. * Fixed interaction with external files on pydev package explorer. What is PyDev? --- PyDev is a plugin that enables users to use Eclipse for Python, Jython and IronPython development -- making Eclipse a first class Python IDE -- It comes with many goodies such as code completion, syntax highlighting, syntax analysis, refactor, debug and many others. Cheers, -- Fabio Zadrozny -- Software Developer PyDev - Python Development Environment for Eclipse http://pydev.org http://pydev.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
RE: Python #ifdef
On 28 May 2013 21:26, Carlos Nepomuceno carlosnepomuc...@outlook.com wrote: Haha! That's it!!! Just realized how funny this can be: ;) ### never to be opened ### def pandoras_box(v): return v/0.0 if customer_didnt_pay(): pandoras_box() #lol 1/0 is, after print, my most common debug statement. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python #ifdef
On 2013-05-28, Carlos Nepomuceno carlosnepomuc...@outlook.com wrote: [...] You're trying to make this a lot harder than it really is: if sys.version_info[0] == 3: def original(n): m = 0 for b in n.to_bytes(6, 'big'): m = 256*m + b return m else: def original(n): something else? Haha! That's it!!! Just realized how funny this can be: ;) Here's the important lesson from this thread: Instead of asking how do I write X in Python where yoy've assumed X is the solution to your problem, you're usually better off asking how to solve the underlying problem in a Pythonic way. IOW, instead of asking about a Python preprocessor (which you have assumed is the solution to the problem because that's how you would do it in C), ask about the actual problem (how to define a function differently depending on Python version). People on this list are very inventive and will expend a surprising amount of time to figure out often too-clever ways to do X because you asked how to do X -- even if doing X is a lousy way to solve your actual problem... When asking how do I solve a problem, it's OK to illustrate that question with an example X of how you would solve it in C or Java or Ruby or Perl or whatever, but remember 1) Not everybody here knows C or Java or Ruby or Perl or whatever, and the person who _does_ know everyting there is to know about solving some particular underlying problem isn't going to go learn a new language so that they can understand your example and figure out what you're trying to accomplish. 2) Programming languages differ. X may be the best way to solve the problem in one language, but it might be an awful way to do it in another language. -- Grant Edwards grant.b.edwardsYow! I'm ANN LANDERS!! at I can SHOPLIFT!! gmail.com -- http://mail.python.org/mailman/listinfo/python-list
RE: Python #ifdef
Date: Tue, 28 May 2013 21:34:36 +0100 Subject: RE: Python #ifdef From: fabiosantos...@gmail.com To: carlosnepomuc...@outlook.com CC: python-list@python.org On 28 May 2013 21:26, Carlos Nepomuceno carlosnepomuc...@outlook.commailto:carlosnepomuc...@outlook.com wrote: Haha! That's it!!! Just realized how funny this can be: ;) ### never to be opened ### def pandoras_box(v): return v/0.0 if customer_didnt_pay(): pandoras_box() #lol 1/0 is, after print, my most common debug statement. What's the best debugger for Python? Have you tried HAP[1]? [1] http://hapdebugger.sourceforge.net/ -- http://mail.python.org/mailman/listinfo/python-list
RE: Python #ifdef
From: invalid@invalid.invalid Subject: Re: Python #ifdef Date: Tue, 28 May 2013 20:42:34 + To: python-list@python.org [...] Here's the important lesson from this thread: Instead of asking how do I write X in Python where yoy've assumed X is the solution to your problem, you're usually better off asking how to solve the underlying problem in a Pythonic way. IOW, instead of asking about a Python preprocessor (which you have assumed is the solution to the problem because that's how you would do it in C), ask about the actual problem (how to define a function differently depending on Python version). People on this list are very inventive and will expend a surprising amount of time to figure out often too-clever ways to do X because you asked how to do X -- even if doing X is a lousy way to solve your actual problem... When asking how do I solve a problem, it's OK to illustrate that question with an example X of how you would solve it in C or Java or Ruby or Perl or whatever, but remember 1) Not everybody here knows C or Java or Ruby or Perl or whatever, and the person who _does_ know everyting there is to know about solving some particular underlying problem isn't going to go learn a new language so that they can understand your example and figure out what you're trying to accomplish. 2) Programming languages differ. X may be the best way to solve the problem in one language, but it might be an awful way to do it in another language. -- Grant Edwards grant.b.edwards Yow! I'm ANN LANDERS!! at I can SHOPLIFT!! gmail.com You're right! Sometimes I hate myself for doing exactly the opposite of what I would like to do! Unfortunately I can't change the thread subject. How do you have invalid@invalid.invalid instead of your email address? -- http://mail.python.org/mailman/listinfo/python-list
Re: How to: Setuptools
I have a great video on how to setup Easy_Install via setuptools as well as pip - http://www.youtube.com/watch?v=MIHYflJwyLk On Mon, May 27, 2013 at 6:32 PM, ray r...@aarden.us wrote: I would like to use easy_install, but can't figure out how to install it. I have 64-bit Python 2.7.5 on Windows 7. Following the instructions on https://pypi.python.org/pypi/setuptools, it says: Download ez_setup.py and run it; it will download the appropriate .egg file and install it for you. (Currently, the provided .exe installer does not support 64-bit versions of Python for Windows, due to a distutils installer compatibility issue Being new to Python, I don't know what it means to run it. I am not sure what I am looking at when I open it as the first line is #!python. Looking down into the content of ez_setup.py, I find: 'setuptools-0.6c10-py2.6.egg': but there is no entry 'setuptools-0.6c10-py2.7.egg': Searching for it, I found a version at: https://pypi.python.org/packages/2.7/s/setuptools/ This appeared to be a linux version, the first line is: #!/bin/sh and the content seems to be encoded. There is an exe at https://pypi.python.org/pypi/setuptools, but the instructions on the page state the .exe won't work for 64-bit installs. Ray -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
RE: Future standard GUI library
From: felip...@gmx.net Subject: Re: Future standard GUI library Date: Tue, 28 May 2013 19:26:55 +0200 To: python-list@python.org Please give me an example of a suitable transport layer for a RPC protocol. I won't give you an example, but just some very basic criteria: - It must be very efficient for very small datagrams Interoperability is much more expensive than efficiency. That's why you won't get the most optimized protocol for speed or size. - It must provide connections What do you mean? - For asynchronous programming it must provide for callbacks No RPC-over-HTTP protocol that I know of does this. XHR implements asynchronous callbacks over HTTP. Besides, no one needs RPC just to logically separate GUI and application layer. And between application logic and database, you use the native database API for the RDBMS in question, of course. The whole idea to centralise application logic (and even the GUI with web applications) is backwards, it dates from the 70s/early 80s when desktop computers weren't able to run application logic. Today, to make an application responsive (minimise latencies and maximise throughput), it's just obvious to *de*-centralise as much as possible. In fact, if Postgres-R was available for production, you could even distribute the persistence and run an entirely serverless application. web applications is so nowadays! All of my recent software development projects (last 10 years) focus on business processes integration. In all of them the BLL (Business Logic Layer), or application logic, is run on server side (as a controller in MVC) due to security and performance reasons. None of my clients want their business rules and internal workflows exposed, so the old ways of the 70/80's ain't gonna change. Sincerely, Wolfgang -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Python #ifdef
On 28/05/2013 20:46, Carlos Nepomuceno wrote: Are there Python 'preprocessor directives'? I'd like to have something like '#ifdef' to mix code from Python 2 and 3 in a single file. Is that possible? How? https://pypi.python.org/pypi/six/1.3.0 -- If you're using GoogleCrap™ please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence -- http://mail.python.org/mailman/listinfo/python-list
Re: Python #ifdef
On Tue, May 28, 2013 at 6:18 PM, Mark Lawrence breamore...@yahoo.co.ukwrote: On 28/05/2013 20:46, Carlos Nepomuceno wrote: Are there Python 'preprocessor directives'? I'd like to have something like '#ifdef' to mix code from Python 2 and 3 in a single file. Is that possible? How? https://pypi.python.org/pypi/**six/1.3.0https://pypi.python.org/pypi/six/1.3.0 -- If you're using GoogleCrap™ please read this http://wiki.python.org/moin/* *GoogleGroupsPython http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence -- http://mail.python.org/**mailman/listinfo/python-listhttp://mail.python.org/mailman/listinfo/python-list my original response was from cell phone. I just answered that you can't do ifdefs, implying that there is no preprocessor in python. I learned a lot of things I didn't know reading the thread, but I wonder if it is a good idea in general to try to write code like this. -- combined 2.x/3.x codebase can be a bear to maintain. I wouldn't do it unless there was some imposing reason that I must. Its not just print() -- that isn't bad, but changes in module names (urllib), arithmetic, and unicode especially make this idea in general, very tricky. Pity the next developer who needs to try to maintain it. So, maybe you CAN do it, but SHOULD you want to do it? -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
RE: Python #ifdef
Date: Tue, 28 May 2013 18:25:59 -0400 Subject: Re: Python #ifdef From: joel.goldst...@gmail.com To: breamore...@yahoo.co.uk CC: python-list@python.org [...] my original response was from cell phone. I just answered that you can't do ifdefs, implying that there is no preprocessor in python. I learned a lot of things I didn't know reading the thread, but I wonder if it is a good idea in general to try to write code like this. -- combined 2.x/3.x codebase can be a bear to maintain. I wouldn't do it unless there was some imposing reason that I must. Its not just print() -- that isn't bad, but changes in module names (urllib), arithmetic, and unicode especially make this idea in general, very tricky. Pity the next developer who needs to try to maintain it. So, maybe you CAN do it, but SHOULD you want to do it? -- Joel Goldstick http://joelgoldstick.com Thanks Joel! In this case I think it does because I would like to have the same short benchmarking script to be runnable by Python 2 and Python 3. The only piece of code that doesn't run on Python 2 is a to_bytes() single call. So it's not a huge maintenance load. ;) I didn't try to write 'portable' code to Python 3 yet. What's the catch? -- http://mail.python.org/mailman/listinfo/python-list
RE: Python #ifdef
On 28 May 2013 21:53, Carlos Nepomuceno carlosnepomuc...@outlook.com wrote: Date: Tue, 28 May 2013 21:34:36 +0100 Subject: RE: Python #ifdef From: fabiosantos...@gmail.com To: carlosnepomuc...@outlook.com CC: python-list@python.org On 28 May 2013 21:26, Carlos Nepomuceno carlosnepomuc...@outlook.commailto:carlosnepomuc...@outlook.com wrote: Haha! That's it!!! Just realized how funny this can be: ;) ### never to be opened ### def pandoras_box(v): return v/0.0 if customer_didnt_pay(): pandoras_box() #lol 1/0 is, after print, my most common debug statement. What's the best debugger for Python? Have you tried HAP[1]? [1] http://hapdebugger.sourceforge.net/ Never saw that, but the remote debugging looks like it adds some flexibility. That said, I don't often use a debugger. When I do, it's pdb. Pdb is not bad at all, and it comes in the stdlib, which makes it readily available in a virtualenv. It's impractical to set more than a breakpoint, but then again I only use a breakpoint at a time. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python #ifdef
Carlos Nepomuceno於 2013年5月29日星期三UTC+8上午3時46分37秒寫道: Are there Python 'preprocessor directives'? I'd like to have something like '#ifdef' to mix code from Python 2 and 3 in a single file. Is that possible? How? Use execfile(filename) at the beginning to get what you want. The .pyc version is preferred. -- http://mail.python.org/mailman/listinfo/python-list
Re: Future standard GUI library
Grant Edwards於 2013年5月29日星期三UTC+8上午2時25分08秒寫道: On 2013-05-28, Wolfgang Keller felip...@gmx.net wrote: Actually productive work of significant intensity at a computer screen. Oh. You mean emacs. -- Grant Edwards grant.b.edwardsYow! Will it improve my at CASH FLOW? gmail.com Check http://www.pyamf.org/index.html for Python +flash in browser applications. Annyway the virtual server part can be obtained from the Adobe system in the cloudy services or whatever. As long as it is scalable in fees to provide services to web users in PCs or mobile phones, then it might be very profitable than 10 to 15 years ago. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python #ifdef
On 5/28/2013 6:25 PM, Joel Goldstick wrote: On Tue, May 28, 2013 at 6:18 PM, Mark Lawrence breamore...@yahoo.co.uk mailto:breamore...@yahoo.co.uk wrote: On 28/05/2013 20:46, Carlos Nepomuceno wrote: I'd like to have something like '#ifdef' to mix code from Python 2 and 3 in a single file. https://pypi.python.org/pypi/__six/1.3.0 https://pypi.python.org/pypi/six/1.3.0 my original response was from cell phone. I just answered that you can't do ifdefs, implying that there is no preprocessor in python. I learned a lot of things I didn't know reading the thread, but I wonder if it is a good idea in general to try to write code like this. -- combined 2.x/3.x codebase can be a bear to maintain. Many people have come to prefer a) a single 23 codebase over b) separate 2 and 3 codebases or c) a single 2 codebase repeatedly converted to a 3 codebase with 2to3. They use 2to3 once (well, a few times) to discover differences that need to be considered. For 2.7 and 3.x, the future imports are enough for some code. The six module handles harder cases. I wouldn't do it unless there was some imposing reason that I must. Its not just print() -- that isn't bad, but changes in module names (urllib), I believe six handles that arithmetic, and from __future__ import integer_division # spelling? handles the only change unicode Use unicode consistently and from __future__ import unicode_literals # spelling? or the re-addition u'' prefix do quite well. Otherwise, do not use things that evaporated, like apply() and classic classes. (Inherit from object if nothing else.) This is all hearsay coming from me ;-). Terry -- http://mail.python.org/mailman/listinfo/python-list
Supporting both 2.x and 3.x in one code base [was Re: Python #ifdef]
On Tue, 28 May 2013 18:25:59 -0400, Joel Goldstick wrote: I wonder if it is a good idea in general to try to write code like this. -- combined 2.x/3.x codebase can be a bear to maintain. Not so much a bear as a tiny little kitten. I wouldn't do it unless there was some imposing reason that I must. Its not just print() -- that isn't bad, but changes in module names (urllib), arithmetic, and unicode especially make this idea in general, very tricky. Pity the next developer who needs to try to maintain it. It's not that hard really. Well, like all things, it depends on the circumstances. If you're reliant on external modules, you *may* have a bad time if those modules are 2.x only or 3.x only, but the standard library and built-ins don't provide too much of a challenge. There's no doubt that supporting 2.x and 3.x in one code base is more difficult that just supporting one or the other, but the difficulty is much less than often supposed. Python 2.7, and to a lesser extent, 2.6, are designed to be as easy to port to 3.x as possible, which has the happy side-effect that they are also relatively easy to write code for them that will also run under 3.x. Many of the differences can be eliminated with a few __future__ imports: from __future__ import division, print_function Differences in behaviour of the built-ins can be eliminated: from future_builtins import * Built-ins such as reduce and cmp that have been moved, or eliminated, can easily be restored: if sys.version = '3': from functools import reduce Or if you prefer a Better To Ask Forgiveness Than Permission approach: try: reduce except NameError: from functools import reduce Name changes of modules are easy to deal with: try: import configparser except ImportError: import ConfigParser as configparser The most difficult difference is the difference between strings in 2.x and 3.x, but if you drop support for Python 3.1 and 3.2, you can write code that works in both 2.7 and 3.3 by using the u syntax. Or just use ASCII literals, which work perfectly in both. There are really only a very few things that cannot be shared between 2.x and 3.x: syntactical features that are only supported by 3.x. So if you're planning on writing code that runs in both 2.x and 3.x, you need to eschew the 3-only features like keyword-only function arguments and function annotations. But that's no different than writing code to support *any* two versions that don't have identical syntax. E.g. 2.4 and 2.5: 2.5 supports ternary if, `a if condition else b`, while 2.4 does not, so if you need to support both, you can't use ternary if. Nearly all the code I write is for 2.4 or better, and I can assure you that the hardest part is supporting 2.4. Adding 3.x doesn't make it much harder. (My hat goes off to those supporting 2.3 through 3.3 in one code base. That is, frankly, astonishing.) Nobody *likes* to have to support really old versions missing the cool syntax that you want to use, but nobody says that you should even try. 3.x doesn't change that. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Python #ifdef
Here're slides from a presentation about writing code that runs on 2.x and 3.x: http://stromberg.dnsalias.org/~dstromberg/Intro-to-Python/ And in case you still want a preprocessor for Python (you likely don't need one this time), here's an example of doing this using the venerable m4: https://pypi.python.org/pypi/red-black-tree-mod . Note the many comments added to keep line numbers consistent. Sent from my android phone. On May 28, 2013 12:47 PM, Carlos Nepomuceno carlosnepomuc...@outlook.com wrote: Are there Python 'preprocessor directives'? I'd like to have something like '#ifdef' to mix code from Python 2 and 3 in a single file. Is that possible? How? -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list