ANN: IMAPClient 0.10
I'm very happy to announce IMAPClient 0.10. IMAPClient is an easy-to-use, Pythonic and complete IMAP client library that is much friendlier to use than the imaplib module in the standard library. It is mature and well tested, including functional tests that check against actual IMAP server implementations. This is the first release to support Python 3. Python versions 2.6, 2.7, 3.2 and 3.3 are now officially supported. Support for Python 2.4 and 2.5 has been dropped. For details on what's changed in this release please see this blog post: http://freshfoo.com/blog/imapclient-0.10 and the news file: https://bitbucket.org/mjs0/imapclient/src/tip/NEWS.rst Related links: * Project home: http://imapclient.freshfoo.com/ * Bitbucket: https://bitbucket.org/mjs0/imapclient/ * PyPI: https://pypi.python.org/pypi/IMAPClient/0.10 * Documentation: https://imapclient.readthedocs.org/ - Menno -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
numba 0.9
Numba 0.9 adds support better math functions for all supported data types (complex and floating). The release also comes with open-sourced generalized ufunc support from numbapro. This allows users to write a NumPy generalized ufunc directly in python and compile it with numba. There is now also support for long double on all platforms. The support comes with a new dependency on llvmmath. Array expressions and their performance have also been improved. Generalized ufuncs: http://numba.pydata.org/numba-doc/0.9/arrays.html#generalized-ufuncs Supported math functions: https://github.com/ContinuumIO/llvmmath/blob/master/llvmmath/RequiredSymbols.txt Download http://numba.pydata.org/download.html Website === http://numba.pydata.org/ Documentation http://numba.pydata.org/numba-doc/0.9/index.html Numba == Numba is an just-in-time specializing compiler which compiles annotated Python and NumPy code to LLVM (through decorators). Its goal is to seamlessly integrate with the Python scientific software stack and produce optimized native code, as well as integrate with native foreign languages. -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
Re: Bools and explicitness [was Re: PyWart: The problem with print]
On Wed, Jun 5, 2013 at 10:25 PM, Russ P. russ.paie...@gmail.com wrote: I recall reading a few years ago that Guido was thinking about adding optional type annotations. I don't know if that went anywhere or not, but I thought it was a good idea. Eventually I got tired of waiting, and I realized that I just wanted a statically typed language, so I started using one. Python 3 has support for arbitrary function argument annotations. The language itself ascribes no special meaning to it, so it's up to the user to add a type-checker (or whatever else they might want to use it for). -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
On Thu, Jun 6, 2013 at 3:54 PM, jmfauth wxjmfa...@gmail.com wrote: (filesystems are just bytes, yeah, whatever...). Sure. You tell me what a proper Unicode rendition of an animated GIF is. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: how to detect the character encoding in a web page ?
On Thu, 06 Jun 2013 03:55:11 +1000, Chris Angelico wrote: The HTTP header is completely out of band. This is the best way to transmit encoding information. Otherwise, you assume 7-bit ASCII and start parsing. Once you find a meta tag, you stop parsing and go back to the top, decoding in the new way. Provided that the meta tag indicates an ASCII-compatible encoding, and you haven't encountered any decode errors due to 8-bit characters, then there's no need to go back to the top. ASCII-compatible covers a huge number of encodings, so it's not actually much of a problem to do this. With slight modifications, you can also handle some almost-ASCII-compatible encodings such as shift-JIS. Personally, I'd start by assuming ISO-8859-1, keep track of which bytes have actually been seen, and only re-start parsing from the top if the encoding change actually affects the interpretation of any of those bytes. And if the encoding isn't even remotely ASCII-compatible, you aren't going to be able to recognise the meta tag in the first place. But I don't think I've ever seen a web page encoded in UTF-16 or EBCDIC. Tools like chardet are meant for the situation where either no encoding is specified or the specified encoding can't be trusted (which is rather common; why else would web browsers have a menu to allow the user to select the encoding?). -- http://mail.python.org/mailman/listinfo/python-list
Re: Errin when executing a cgi script that sets a cookie in the browser
root@nikos [~]# chmod 755 /var/log root@nikos [~]# chmod 755 /var/log/httpd root@nikos [~]# chmod 666 /var/log/httpd/suexec.log root@nikos [~]# chmod 755 /usr/local/apache root@nikos [~]# chmod 755 /usr/local/apache/logs/ root@nikos [~]# chmod 666 /usr/local/apache/logs/error_log and then execute via browser: http://superhost.gr/cgi-bin/koukos.py still same error appearing: [Thu Jun 06 09:23:54 2013] [error] [client 79.103.41.173] suexec failure: could not open log file [Thu Jun 06 09:23:54 2013] [error] [client 79.103.41.173] fopen: Permission denied [Thu Jun 06 09:23:54 2013] [error] [client 79.103.41.173] Premature end of script headers: koukos.py -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
Yes this is a linxu issue although locale is se to utf-8 root@nikos [~]# locale LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 LC_NUMERIC=en_US.UTF-8 LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 LC_PAPER=en_US.UTF-8 LC_NAME=en_US.UTF-8 LC_ADDRESS=en_US.UTF-8 LC_TELEPHONE=en_US.UTF-8 LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=en_US.UTF-8 LC_ALL= root@nikos [~]# Since 'locale' is set to 'utf-8' why when i: 'mv 'Euxi tou Ihsou.mp3' 'Ευχή του Ιησού.mp3' lead to that unknown encoded bytestream '\305\365\367\336\\364\357\365\311\347\363\357\375.mp3' which isn't by default an utf-8 bytestream as locale indicated and python expected? how 'files.py' is supposed to read this file now using: # Compute a set of current fullpaths fullpaths = set() path = /home/nikos/public_html/data/apps/ for root, dirs, files in os.walk(path): for fullpath in files: fullpaths.add( os.path.join(root, fullpath) ) -- http://mail.python.org/mailman/listinfo/python-list
Re: how to detect the character encoding in a web page ?
On Thu, Jun 6, 2013 at 4:22 PM, Nobody nob...@nowhere.com wrote: On Thu, 06 Jun 2013 03:55:11 +1000, Chris Angelico wrote: The HTTP header is completely out of band. This is the best way to transmit encoding information. Otherwise, you assume 7-bit ASCII and start parsing. Once you find a meta tag, you stop parsing and go back to the top, decoding in the new way. Provided that the meta tag indicates an ASCII-compatible encoding, and you haven't encountered any decode errors due to 8-bit characters, then there's no need to go back to the top. Technically and conceptually, you go back to the start and re-parse. Sure, you might optimize that if you can, but not every parser will, hence it's advisable to put the content-type as early as possible. ASCII-compatible covers a huge number of encodings, so it's not actually much of a problem to do this. With slight modifications, you can also handle some almost-ASCII-compatible encodings such as shift-JIS. Personally, I'd start by assuming ISO-8859-1, keep track of which bytes have actually been seen, and only re-start parsing from the top if the encoding change actually affects the interpretation of any of those bytes. Hrm, it'd be equally valid to guess UTF-8. But as long as you're prepared to re-parse after finding the content-type, that's just a choice of optimization and has no real impact. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
HOW DOES ISLAM DIFFER FROM OTHER FAITHS? (PART 1 OF 2)
How Does Islam Differ from other Faiths? (part 1 of 2) Description: Some of the Unique Features of Islam not found in other belief systems and ways of life. B Simplicity, Rationality and Practicality Islam is a religion without any mythology. Its teachings are simple and intelligible. It is free from superstitions and irrational beliefs. The oneness of God, the prophethood of Muhammad, and the concept of life after death are the basic articles of its faith. They are based on reason and sound logic. All of the teachings of Islam flow from those basic beliefs and are simple and straightforward. There is no hierarchy of priests, no farfetched abstractions, no complicated rites or rituals. Everybody may approach the Quran directly and translate its dictates into practice. Islam awakens in man the faculty of reason and exhorts him to use his intellect. It enjoins him to see things in the light of reality. The Quran advises him to seek knowledge and invoke God to expand his awareness: Say ‘O, my Lord! Advance me in knowledge. (Quran 20: 114) God also says: “Are those who know equal with those who know not? But only men of understanding will pay heed.” (Quran 39: 9) It is reported that the Prophet, may the mercy and blessings of God be upon him, said that: “He who leaves his home in search of knowledge (walks) in the path of God.” (At-Tirmidhi) and that, “Seeking knowledge is obligatory upon every Muslim.” (Ibn Majah and al- Bayhaqi) This is how Islam brings man out of the world of superstition and darkness and initiates him into the world of knowledge and light. Again, Islam is a practical religion and does not allow indulgence in empty and futile theorizing. It says that faith is not a mere profession of beliefs, but rather that it is the very mainspring of life. Righteous conduct must follow belief in God. Religion is something to be practiced and not an object of mere lip service. The Quran says: “Those who believe and act righteously, joy is for them, and a blissful home to return to.” (Quran 13: 29) The Prophet is also reported to have said: “God does not accept belief if it is not expressed in deeds, and does not accept deeds if they do not conform to belief.” (At-Tabarani) Thus Islam’s simplicity, rationality and practicality are what characterize Islam as a unique and true religion. Unity of Matter and Spirit A unique feature of Islam is that it does not divide life into watertight compartments of matter and spirit. It stands not for denial of life but for the fulfillment of life. Islam does not believe in asceticism. It does not ask man to avoid material things. It holds that spiritual elevation is to be achieved by living piously in the rough and tumble of life, not by renouncing the world. The Quran advises us to pray as follows: “Our Lord! Give us something fine in this world as well as something fine in the Hereafter.” (Quran 2:201) But in making use of life luxuries, Islam advises man to be moderate and keep away from extravagance, God says: “…and eat and drink and be not extravagant; surely He does not love the extravagant.” (Quran 7:31) On this aspect of moderation, the Prophet said: “Observe fasting and break it (at the proper time) and stand in prayer and devotion (in the night) and have sleep, for your body has its right over you, and your eyes have rights over you, and your wife has a claim upon you, and the person who pays a visit to you has a claim upon you.” Thus, Islam does not admit any separation between “material” and “moral,” “mundane” and “spiritual” life, and enjoins man to devote all of his energies to the reconstruction of life on healthy moral foundations. It teaches him that moral and material powers must be welded together and that spiritual salvation can be achieved by using material resources for the good of man in the service of just ends and not by living a life of asceticism or by running away from the challenges of life. The world has suffered at the hands of the one-sidedness of many other religions and ideologies. Some have laid emphasis on the spiritual side of life but have ignored its material and mundane aspects. They have looked upon the world as an illusion, a deception, and a trap. On the other hand, materialistic ideologies have totally ignored the spiritual and moral side of life and have dismissed it as fictitious and imaginary. Both of these attitudes have resulted in disaster, for they have robbed mankind of peace, contentment, and tranquility. Even today, the imbalance is manifested in one or the other direction. The French scientist Dr. De Brogbi rightly says: “The danger inherent in too intense a material civilization is to that civilization itself; it is the disequilibria which would result if a parallel development of the spiritual life were to fail to provide the needed balance.” Christianity erred on one extreme, whereas modern western civilization, in both of its variants of secular
Re: Changing filenames from Greeklish = Greek (subprocess complain)
Am 05.06.2013 18:44, schrieb MRAB: From the previous posts I guessed that the filename might be encoded using ISO-8859-7: s = b\305\365\367\336\ \364\357\365\ \311\347\363\357\375.mp3 s.decode(iso-8859-7) 'Ευχή\\ του\\ Ιησού.mp3' Yes, that looks the same. Most probably, his terminal is set to ISO-8859-7, so that when he issues the rename command on the command-line of his shell session, the mv command gets a stream of bytes as the new file name which happens to be the ISO-8859-7 encoding of the file name he'd like the file to have. This is what's stored on disk. So, his biggest problem isn't that the operating system is encoding agnostic wrt. filenames (i.e., treats them as a stream of bytes), but rather that he's using an ISO-7 terminal window when having set up UTF-8 as his operating system locale and expects filenames to be encoded in UTF-8 when he's not passing in UTF-8 byte streams from his client computer at all. -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
On 06/06/2013 07:11, Chris Angelico wrote: On Thu, Jun 6, 2013 at 3:54 PM, jmfauth wxjmfa...@gmail.com wrote: (filesystems are just bytes, yeah, whatever...). Sure. You tell me what a proper Unicode rendition of an animated GIF is. ChrisA It's obviously one that doesn't use the flawed Python Flexible String Representation :) -- Steve is going for the pink ball - and for those of you who are watching in black and white, the pink is next to the green. Snooker commentator 'Whispering' Ted Lowe. Mark Lawrence -- http://mail.python.org/mailman/listinfo/python-list
Re: Bools and explicitness [was Re: PyWart: The problem with print]
On Thu, 06 Jun 2013 12:29:44 +1000, Chris Angelico wrote: On Thu, Jun 6, 2013 at 11:56 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Wed, 05 Jun 2013 14:59:31 -0700, Russ P. wrote: As for Python, my experience with it is that, as your application grows, you start getting confused about what the argument types are or are supposed to be. Whereas people never get confused about the arguments in static typed languages? The only difference is whether the compiler tells you that you've passed the wrong type, or your unit test tells you that you've passed the wrong type. What, you don't have unit tests? Then how do you know that the code does the right thing when passed data of the right type? Adding an extra couple of unit tests is not that big a burden. The valid type(s) for an argument can be divided into two categories: Those the compiler can check for, and those the compiler can't check for. Some languages have more in the first category than others, but what compiler can prove that a string is an HTML-special-characters-escaped string? In a very few languages, the compiler can insist that an integer be between 7 and 30, but there'll always be some things you can't demonstrate with a function signature. That said, though, I do like being able to make at least *some* declaration there. It helps catch certain types of error. *shrug* I don't terribly miss type declarations. Function argument declarations are a bit simpler in Pascal, compared to Python: Function Add(A, B : Integer) : Integer; Begin Add := A + B; End; versus def add(a, b): if not (isinstance(a, int) and isinstance(b, int)): raise TypeError return a + b but not that much simpler. And while Python can trivially support multiple types, Pascal cannot. (Some other static typed languages may.) Whatever benefit there is in declaring the type of a function is lost due to the inability to duck-type or program to an interface. There's no type that says any object with a 'next' method, for example. And having to declare local variables is a PITA with little benefit. Give me a language with type inference, and a nice, easy way to keep duck- typing, and I'll reconsider. But until then, I don't believe the benefit of static types comes even close to paying for the extra effort. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Speeding up Python
Comparing CPython, PyPy, SciPy, Parakeet and Numba for writing image filters: http://www.phi-node.com/2013/06/faster-morphological-image-filters-in.html -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Bools and explicitness [was Re: PyWart: The problem with print]
On Thu, Jun 6, 2013 at 7:29 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: Whatever benefit there is in declaring the type of a function is lost due to the inability to duck-type or program to an interface. There's no type that says any object with a 'next' method, for example. And having to declare local variables is a PITA with little benefit. Give me a language with type inference, and a nice, easy way to keep duck- typing, and I'll reconsider. But until then, I don't believe the benefit of static types comes even close to paying for the extra effort. Here are some classic ways to do the multiple-types-accepted option. //C++ style: overloading int max(int a,int b) {return ab ? a : b;} float max(float a,float b) {return ab ? a : b;} //C++ also lets you go for templates, but leave that aside //Pike style: piped types int|float max(int|float a,int|float b) {return ab ? a : b;} //This lets you write one lot of code but doesn't let //you declare that both args must be the same type # Python style: accept anything, then (maybe) check def max(a,b): return a if ab else b //Pike does this too: mixed max(mixed a,mixed b) {return ab ? a : b;} /* So does C, but only with pointers: */ void *max(void *a,void *b) {... uhh, this is nontrivial actually ...} For the accept any object that has a next() method sorts of rules, I don't know of any really viable system that does that usefully. The concept of implementing interfaces in Java comes close, but the class author has to declare that it's implementing some named interface. In theory there could be something that deduces the validity from the given structure, but I'm not aware of any language that does this. But it would let you do stuff like this (prototyped in Python): class Integers: def __init__(self): self.value=0 def next(self): self.value+=1 return self.value interface Iterable: next(self) def grab_three_values(Iterable iter): return iter.next(),iter.next(),iter.next() With a language that checks these sorts of things at compile time, it's not a big deal to test. With something fully dynamic like Python, it's probably not worth the effort. But maybe checks like this could be useful to something like Coverity. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
The system cannot find the path specified[...] wxPython strange bug
Hi, I'm developing plugin for sublime text 2. I'm importing wxPython module and sometimes I get following error: [code] Reloading plugin C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\User\my_plugin.py Traceback (most recent call last): File .\sublime_plugin.py, line 62, in reload_plugin File .\my_plugin.py, line 10, in module import wx File string, line 9, in __init__ WindowsError: [Error 3] The system cannot find the path specified: u'/C/Users/User/AppData/Roaming/Sublime Text 2/Packages/User/wx_distr/wx/tools/Editra/plugins' [/code] But after some time, if I reload my plugin few times(it's random), it launches properly. It seems very strange to me, anyone have any ideas? Thanks, Maciej. -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
On 05Jun2013 11:43, =?utf-8?B?zp3Or866zr/PgiDOk866z4EzM866?= nikos.gr...@gmail.com wrote: | Τη Τετάρτη, 5 Ιουνίου 2013 9:32:15 μ.μ. UTC+3, ο χρήστης MRAB έγραψε: | Using Python, I think you could get the filenames using os.listdir, | passing the directory name as a bytestring so that it'll return the | names as bytestrings. | | Then, for each name, you could decode from its current encoding and | encode to UTF-8 and rename the file, passing the old and new paths to | os.rename as bytestrings. | | Iam not sure i follow: | | Change this: | | # Compute a set of current fullpaths | fullpaths = set() | path = /home/nikos/public_html/data/apps/ | | for root, dirs, files in os.walk(path): [...] Have a read of this: http://docs.python.org/3/library/os.html#os.listdir The UNIX API accepts bytes for filenames and paths. Python 3 strs are sequences of Unicode code points. If you try to open a file or directory on a UNIX system using a Python str, that string must be converted to a sequence of bytes before being handed to the OS. This is done implicitly using your locale settings if you just use a str. However, if you pass a bytes to open or listdir, this conversion does not take place. You put bytes in and in the case of listdir you get bytes out. You can work on pathnames in bytes and never concern yourself with encode/decode at all. In this way you can write code that does not care about the translation between Unicode and some arbitrary byte encoding. Of course, the issue will still arise when accepting user input; your shell has done exactly this kind of thing when you renamed your MP3 file. But it is possible to write pure utility code that doesn't care about filenames as Unicode or str if you work purely in bytes. Regarding user filenames, the common policy these days is to use utf-8 throughout. Of course you need to get everything into that regime to start with. -- Cameron Simpson c...@zip.com.au ...but C++ gloggles the cheesewad, thus causing a type conflict. - David Jevans, jev...@apple.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
Τη Πέμπτη, 6 Ιουνίου 2013 11:50:55 π.μ. UTC+3, ο χρήστης Heiko Wundram έγραψε: Am 05.06.2013 18:44, schrieb MRAB: From the previous posts I guessed that the filename might be encoded using ISO-8859-7: s = b\305\365\367\336\ \364\357\365\ \311\347\363\357\375.mp3 s.decode(iso-8859-7) 'οΏ½οΏ½οΏ½οΏ½\\ οΏ½οΏ½οΏ½\\ οΏ½οΏ½οΏ½οΏ½οΏ½.mp3' Yes, that looks the same. Most probably, his terminal is set to ISO-8859-7, so that when he issues the rename command on the command-line of his shell session, the mv command gets a stream of bytes as the new file name which happens to be the ISO-8859-7 encoding of the file name he'd like the file to have. This is what's stored on disk. So, his biggest problem isn't that the operating system is encoding agnostic wrt. filenames (i.e., treats them as a stream of bytes), but rather that he's using an ISO-7 terminal window when having set up UTF-8 as his operating system locale and expects filenames to be encoded in UTF-8 when he's not passing in UTF-8 byte streams from his client computer at all. -- --- Heiko. ni...@superhost.gr [~/www/data/apps]# ls -l | file - /dev/stdin: ASCII text # Compute a set of current fullpaths fullpaths = set() path = /home/nikos/public_html/data/apps/ for root, dirs, files in os.walk(path): for fullpath in files: fullpaths.add( os.path.join(root, fullpath) ) [Thu Jun 06 13:34:19 2013] [error] [client 79.103.41.173] cur.execute('''SELECT url FROM files WHERE url = %s''', fullpath.encode('iso-8859-7') ) [Thu Jun 06 13:34:19 2013] [error] [client 79.103.41.173] File /usr/local/lib/python3.3/encodings/iso8859_7.py, line 12, in encode [Thu Jun 06 13:34:19 2013] [error] [client 79.103.41.173] return codecs.charmap_encode(input,errors,encoding_table) [Thu Jun 06 13:34:19 2013] [error] [client 79.103.41.173] UnicodeEncodeError: 'charmap' codec can't encode characters in position 34-37: character maps to undefined [Thu Jun 06 13:27:17 2013] [error] [client 79.103.41.173] Traceback (most recent call last): [Thu Jun 06 13:27:17 2013] [error] [client 79.103.41.173] File files.py, line 73, in module [Thu Jun 06 13:27:17 2013] [error] [client 79.103.41.173] cur.execute('''SELECT url FROM files WHERE url = %s''', fullpath.decode('iso-8859-7') ) [Thu Jun 06 13:27:17 2013] [error] [client 79.103.41.173] AttributeError: 'str' object has no attribute 'decode' Same when i encode in latin -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
Am 06.06.2013 12:35, schrieb Νικόλαος Κούρας: ni...@superhost.gr [~/www/data/apps]# ls -l | file - /dev/stdin: ASCII text Did you actually try to understand what I wrote? -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
How to store a variable when a script is executing for next time execution?
hi, I am running a python script and it will create a file name like filename0.0.0 and If I run it again then new file will create one more like filename0.0.1.. my code is- i = 0 for i in range(1000): try: with open('filename%d.%d.%d.json'%(0,0,i,)): pass continue except IOError: dataFile = file('filename%d.%d.%d.json'%(0,0,i,), 'a+') break But It will take more time after creating many files, So i want to store value of last var i in a variable so that when i run my script again then I can use it. for example- my last created file is filename0.0.27 then it should store 27 in a variable and when i run again then new file should be created 0.0.28 according to last value 27, so that i could save time and it can create file fast.. Please give me suggestion for it.. How is it possible? Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Errin when executing a cgi script that sets a cookie in the browser
I have re-enabled 'suexec' and set cgi as default phphandler and then trying: print( cookie ) print( '''Content-type: text/html; charset=utf-8\n''' ) print( message ) - ni...@superhost.gr [~/www/data/apps]# [Thu Jun 06 13:51:28 2013] [error] [client 79.103.41.173] suexec failure: could not open log file [Thu Jun 06 13:51:28 2013] [error] [client 79.103.41.173] fopen: Permission denied [Thu Jun 06 13:51:28 2013] [error] [client 79.103.41.173] Premature end of script headers: koukos.py Even if dissable/enable suexec still this output error. -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
Heiko, the ssh client i used to 'mv' the .mp3 was putty.Do you mean that putty is responsible for the encoding mess? the rename command on the command-line of his shell session, the mv command gets a stream of bytes as the new file name which happens to be the ISO-8859-7 encoding of the file name he'd like the file to have. This is what's stored on disk. So, his biggest problem isn't that the operating system is encoding agnostic wrt. filenames (i.e., treats them as a stream of bytes), but rather that he's using an ISO-7 terminal window when having set up UTF-8 as his operating system locale and expects filenames to be encoded in UTF-8 when he's not passing in UTF-8 byte streams from his client computer at all. the rename command on the command-line of his shell session, the mv command gets a stream of bytes as the new file name which happens to be the ISO-8859-7 encoding of the file name he'd like the file to have. This is what's stored on disk. So, his biggest problem isn't that the operating system is encoding agnostic wrt. filenames (i.e., treats them as a stream of bytes), but rather that he's using an ISO-7 terminal window when having set up UTF-8 as his operating system locale and expects filenames to be encoded in UTF-8 when he's not passing in UTF-8 byte streams from his client the rename command on the command-line of his shell session, the mv command gets a stream of bytes as the new file name which happens to be the ISO-8859-7 encoding of the file name he'd like the file to have. This is what's stored on disk. So, his biggest problem isn't that the operating system is encoding agnostic wrt. filenames (i.e., treats them as a stream of bytes), but rather that he's using an ISO-7 terminal window when having set up UTF-8 as his operating system locale and expects filenames to be encoded in UTF-8 when he's not passing in UTF-8 byte streams from his client computer at all. the rename command on the command-line of his shell session, the mv command gets a stream of bytes as the new file name which happens to be the ISO-8859-7 encoding of the file name he'd like the file to have. This is what's stored on disk. So, his biggest problem isn't that the operating system is encoding agnostic wrt. filenames (i.e., treats them as a stream of bytes), but rather that he's using an ISO-7 terminal window when having set up UTF-8 as his operating system locale and expects filenames to be encoded in UTF-8 when he's not passing in UTF-8 byte streams from his client computer at all. the rename command on the command-line of his shell session, the mv command gets a stream of bytes as the new file name which happens to be the ISO-8859-7 encoding of the file name he'd like the file to have. This is what's stored on disk. So, his biggest problem isn't that the operating system is encoding agnostic wrt. filenames (i.e., treats them as a stream of bytes), but rather that he's using an ISO-7 terminal window when having set up UTF-8 as his operating system locale and expects filenames to be encoded in UTF-8 when he's not passing in UTF-8 byte streams from his client computer at all. -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
Am 06.06.2013 13:00, schrieb Νικόλαος Κούρας: Heiko, the ssh client i used to 'mv' the .mp3 was putty.Do you mean that putty is responsible for the encoding mess? Exactly. Check the encoding that putty uses for the terminal session. If it doesn't use UTF-8, switch your terminal session to UTF-8 and try the rename again. If it does, try to use another terminal client (I recommend the Cygwin-Suite). -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: Bools and explicitness [was Re: PyWart: The problem with print]
06.06.13 12:45, Chris Angelico написав(ла): For the accept any object that has a next() method sorts of rules, I don't know of any really viable system that does that usefully. The concept of implementing interfaces in Java comes close, but the class author has to declare that it's implementing some named interface. In theory there could be something that deduces the validity from the given structure, but I'm not aware of any language that does this. Go? -- http://mail.python.org/mailman/listinfo/python-list
Re: The system cannot find the path specified[...] wxPython strange bug
It seems like it constructs path wrongly(as I have seen before), but why sometimes it works and sometimes doesn't(so maybe sometimes it generates path correctly)? -- http://mail.python.org/mailman/listinfo/python-list
Re: How to store a variable when a script is executing for next time execution?
On 06Jun2013 03:50, Avnesh Shakya avnesh.n...@gmail.com wrote: | hi, |I am running a python script and it will create a file name like filename0.0.0 and If I run it again then new file will create one more like filename0.0.1.. my code is- | | i = 0 | for i in range(1000): | try: | with open('filename%d.%d.%d.json'%(0,0,i,)): pass | continue | except IOError: | dataFile = file('filename%d.%d.%d.json'%(0,0,i,), 'a+') | break | But It will take more time after creating many files, So i want to store value of last var i in a variable so that when i run my script again then I can use it. for example- | my last created file is filename0.0.27 then it should store 27 in a variable and when i run again then new file should be created 0.0.28 according to last value 27, so that i could save time and it can create file fast.. | | Please give me suggestion for it.. How is it possible? Write it to a file? Read the file next time the script runs? BTW, trying to open zillions of files is slow. But using listdir to read the directory you can see all the names. Pick the next free one (and then test anyway). -- Cameron Simpson c...@zip.com.au The mark must be robust enough to survive MP3 transmission over the Internet, but remain inaudible when played on the yet to be launched DVD-Audio players. - the SDMI audio watermarkers literally ask for the impossible, since all audio compressors aim to pass _only_ human perceptible data http://www.newscientist.com/news/news.jsp?id=ns224836 -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
Τη Πέμπτη, 6 Ιουνίου 2013 1:24:16 μ.μ. UTC+3, ο χρήστης Cameron Simpson έγραψε: On 05Jun2013 11:43, =?utf-8?B?zp3Or866zr/PgiDOk866z4EzM866?= nikos.gr...@gmail.com wrote: | Τη Τετάρτη, 5 Ιουνίου 2013 9:32:15 μ.μ. UTC+3, ο χρήστης MRAB έγραψε: | Using Python, I think you could get the filenames using os.listdir, | passing the directory name as a bytestring so that it'll return the | names as bytestrings. | | Then, for each name, you could decode from its current encoding and | encode to UTF-8 and rename the file, passing the old and new paths to | os.rename as bytestrings. | | Iam not sure i follow: | | Change this: | | # Compute a set of current fullpaths | fullpaths = set() | path = /home/nikos/public_html/data/apps/ | | for root, dirs, files in os.walk(path): [...] Have a read of this: http://docs.python.org/3/library/os.html#os.listdir The UNIX API accepts bytes for filenames and paths. Python 3 strs are sequences of Unicode code points. If you try to open a file or directory on a UNIX system using a Python str, that string must be converted to a sequence of bytes before being handed to the OS. This is done implicitly using your locale settings if you just use a str. However, if you pass a bytes to open or listdir, this conversion does not take place. You put bytes in and in the case of listdir you get bytes out. You can work on pathnames in bytes and never concern yourself with encode/decode at all. In this way you can write code that does not care about the translation between Unicode and some arbitrary byte encoding. Of course, the issue will still arise when accepting user input; your shell has done exactly this kind of thing when you renamed your MP3 file. But it is possible to write pure utility code that doesn't care about filenames as Unicode or str if you work purely in bytes. Regarding user filenames, the common policy these days is to use utf-8 throughout. Of course you need to get everything into that regime to start with Τη Πέμπτη, 6 Ιουνίου 2013 1:24:16 μ.μ. UTC+3, ο χρήστης Cameron Simpson έγραψε: On 05Jun2013 11:43, =?utf-8?B?zp3Or866zr/PgiDOk866z4EzM866?= nikos.gr...@gmail.com wrote: | Τη Τετάρτη, 5 Ιουνίου 2013 9:32:15 μ.μ. UTC+3, ο χρήστης MRAB έγραψε: | Using Python, I think you could get the filenames using os.listdir, | passing the directory name as a bytestring so that it'll return the | names as bytestrings. | | Then, for each name, you could decode from its current encoding and | encode to UTF-8 and rename the file, passing the old and new paths to | os.rename as bytestrings. | | Iam not sure i follow: | | Change this: | | # Compute a set of current fullpaths | fullpaths = set() | path = /home/nikos/public_html/data/apps/ | | for root, dirs, files in os.walk(path): [...] Have a read of this: http://docs.python.org/3/library/os.html#os.listdir The UNIX API accepts bytes for filenames and paths. Python 3 strs are sequences of Unicode code points. If you try to open a file or directory on a UNIX system using a Python str, that string must be converted to a sequence of bytes before being handed to the OS. This is done implicitly using your locale settings if you just use a str. However, if you pass a bytes to open or listdir, this conversion does not take place. You put bytes in and in the case of listdir you get bytes out. You can work on pathnames in bytes and never concern yourself with encode/decode at all. In this way you can write code that does not care about the translation between Unicode and some arbitrary byte encoding. Of course, the issue will still arise when accepting user input; your shell has done exactly this kind of thing when you renamed your MP3 file. But it is possible to write pure utility code that doesn't care about filenames as Unicode or str if you work purely in bytes. Regarding user filenames, the common policy these days is to use utf-8 throughout. Of course you need to get everything into that regime to start with. So i i nee to use os.listdir() to grab those filenames into bytes. okey. So by changing this to: fullpaths = set() path = /home/nikos/public_html/data/apps/ for root, dirs, files in os.walk(path): for fullpath in files: fullpaths.add( os.path.join(root, fullpath) ) # Compute a set of current fullpaths fullpaths = os.listdir( '/home/nikos/public_html/data/apps/' ) # Load'em for fullpath in fullpaths: try: # Check the presence of a file against the database and insert if it doesn't exist cur.execute('''SELECT url FROM files WHERE url = %s''', (fullpath,) ) data = cur.fetchone()#URL
Re: Changing filenames from Greeklish = Greek (subprocess complain)
Τη Πέμπτη, 6 Ιουνίου 2013 2:09:22 μ.μ. UTC+3, ο χρήστης Heiko Wundram έγραψε: Am 06.06.2013 13:00, schrieb Νικόλαος Κούρας: Heiko, the ssh client i used to 'mv' the .mp3 was putty.Do you mean that putty is responsible for the encoding mess? Exactly. Check the encoding that putty uses for the terminal session. If it doesn't use UTF-8, switch your terminal session to UTF-8 and try the rename again. If it does, try to use another terminal client (I recommend the Cygwin-Suite). Okey, indeed it was using greek-sio encoding, i changed it to uf-8 and reopned the terminal session. ni...@superhost.gr [~/www/data/apps]# mv *.mp3 'Ευχή του Ιησού.mp3' mv: `\305\365\367\336 \364\357\365 \311\347\363\357\375.mp3' and `\305\365\367\3 36 \364\357\365 \311\347\363\357\375.mp3' are the same file ni...@superhost.gr [~/www/data/apps]# mv *.mp3 'Ευχή του Ιησού.mp33' ni...@superhost.gr [~/www/data/apps]# mv *.mp33 'Ευχή του Ιησού.mp3' ni...@superhost.gr [~/www/data/apps]# ls -l total 368548 drwxr-xr-x 2 nikos nikos 4096 Jun 6 14:22 ./ drwxr-xr-x 6 nikos nikos 4096 May 26 21:13 ../ -rwxr-xr-x 1 nikos nikos 13157283 Mar 17 12:57 100\ Mythoi\ tou\ Aiswpou.pdf* -rwxr-xr-x 1 nikos nikos 29524686 Mar 11 18:17 Anekdotologio.exe* -rw-r--r-- 1 nikos nikos 42413964 Jun 2 20:29 Battleship.exe -rw-r--r-- 1 nikos nikos 236032 Jun 4 14:10 \323\352\335\370\357\365\ \335\35 5\341\355\ \341\361\351\350\354\374.exe -rwxr-xr-x 1 nikos nikos 66896732 Mar 17 13:13 Kosmas\ o\ Aitwlos\ -\ Profiteies .pdf* -rw-r--r-- 1 nikos nikos 51819750 Jun 2 20:04 Luxor\ Evolved.exe -rw-r--r-- 1 nikos nikos 60571648 Jun 2 14:59 Monopoly.exe -rw-r--r-- 1 nikos nikos 3511233 Jun 4 14:11 \305\365\367\336\ \364\357\365\ \ 311\347\363\357\375.mp3 -rwxr-xr-x 1 nikos nikos 1788164 Mar 14 11:31 Online\ Movie\ Player.zip* -rw-r--r-- 1 nikos nikos 5277287 Jun 1 18:35 O\ Nomos\ tou\ Merfy\ v1-2-3.zip -rwxr-xr-x 1 nikos nikos 16383001 Jun 22 2010 Orthodoxo\ Imerologio.exe* -rw-r--r-- 1 nikos nikos 6084806 Jun 1 18:22 Pac-Man.exe -rw-r--r-- 1 nikos nikos 25476584 Jun 2 19:50 Scrabble.exe -rwxr-xr-x 1 nikos nikos 49141166 Mar 17 12:48 To\ 1o\ mou\ vivlio\ gia\ to\ ska ki.pdf* -rwxr-xr-x 1 nikos nikos 3298310 Mar 17 12:45 Vivlos\ gia\ Atheofovous.pdf* -rw-r--r-- 1 nikos nikos 1764864 May 29 21:50 V-Radio\ v2.4.msi ni...@superhost.gr [~/www/data/apps]# ls *.mp3 | file - /dev/stdin: ASCII text ni...@superhost.gr [~/www/data/apps]# still same error. -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
Am 06.06.2013 13:24, schrieb Νικόλαος Κούρας: ni...@superhost.gr [~/www/data/apps]# ls *.mp3 | file - /dev/stdin: ASCII text Again, did you actually read (and try to understand) what I wrote? I said to redo the rename after you change your terminal session to UTF-8. -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
# Compute a set of current fullpaths fullpaths = os.listdir( '/home/nikos/public_html/data/apps/' ) # Load'em for fullpath in fullpaths: try: # Check the presence of a file against the database and insert if it doesn't exist cur.execute('''SELECT url FROM files WHERE url = %s''', fullpath.encode('utf-8') ) data = cur.fetchone()#URL is unique, so should only be one print( fullpath.encode('utf-8') ) Now why this does not print out the filenames when iterated in the for loop? One step forward is that when i run it liek this no error is being displyed in the error log. Please help, i ahve tried os.listdir() as Cameron suggested. -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
On 06/06/2013 04:43, Νικόλαος Κούρας wrote: Τη Τετάρτη, 5 Ιουνίου 2013 9:43:18 μ.μ. UTC+3, ο χρήστης Νικόλαος Κούρας έγραψε: Τη Τετάρτη, 5 Ιουνίου 2013 9:32:15 μ.μ. UTC+3, ο χρήστης MRAB έγραψε: On 05/06/2013 18:43, οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½ οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½ wrote: οΏ½οΏ½ οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½, 5 οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½ 2013 8:56:36 οΏ½.οΏ½. UTC+3, οΏ½ οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½ Steven D'Aprano οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½: Somehow, I don't know how because I didn't see it happen, you have one or more files in that directory where the file name as bytes is invalid when decoded as UTF-8, but your system is set to use UTF-8. So to fix this you need to rename the file using some tool that doesn't care quite so much about encodings. Use the bash command line to rename each file in turn until the problem goes away. ' leade to that unknown encoding of this bytestream '\305\365\367\336\ \364\357\365\ \311\347\363\357\375.mp3' But please tell me Steven what linux tool you think it can encode the weird filename to proper 'οΏ½οΏ½οΏ½οΏ½ οΏ½οΏ½οΏ½ οΏ½οΏ½οΏ½οΏ½οΏ½.mp3' utf-8? or we cna write a script as i suggested to decode back the bytestream using all sorts of available decode charsets boiling down to the original greek letters. Actually you were correct i was typing greek and is aw the fileneme here in gogole groups as: But renaming ia hsell access like 'mv 'Euxi tou Ihsou.mp3' 'οΏ½οΏ½οΏ½οΏ½ οΏ½οΏ½οΏ½ οΏ½οΏ½οΏ½οΏ½οΏ½.mp3 so maybe the filenames have to be decoded to greek-iso but then agian the contain both greek letters but their extension are in english chars like '.mp3' Using Python, I think you could get the filenames using os.listdir, passing the directory name as a bytestring so that it'll return the names as bytestrings. Then, for each name, you could decode from its current encoding and encode to UTF-8 and rename the file, passing the old and new paths to os.rename as bytestrings. Iam not sure i follow: Change this: # Compute a set of current fullpaths fullpaths = set() path = /home/nikos/public_html/data/apps/ for root, dirs, files in os.walk(path): for fullpath in files: fullpaths.add( os.path.join(root, fullpath) ) to what to make the full url readable by files.py? MRAB can you please explain in more clarity your idea of solution? I was suggesting a way to rename the files so that their names are encoded in UTF-8 (they appear to be encoded in ISO-8859-7). You MUST TEST IT thoroughly first, of course, before trying it on the actual files. It could go something like this: import os # Give the path as a bytestring so that we'll get the names as bytestrings. root_folder = b/home/nikos/public_html/data/apps/ # Setting TESTING to True will make it print out what renamings it will do, but # not actually do them. TESTING = True # Walk through the files. for root, dirs, files in os.walk(root_folder): for name in files: try: # Is this name encoded in UTF-8? name.decode(utf-8) except UnicodeDecodeError: # Decoding from UTF- failed, which means that the name is not valid # UTF-8. # It appears (from elsewhere) that the names are encoded in # ISO-8859-7, so decode from that and re-encode to UTF-8. new_name = name.decode(iso-8859-7).encode(utf-8) old_path = os.path.join(root, name) new_path = os.path.join(root, new_name) if TESTING: print(Will rename {!r} to {!r}.format(old_path, new_path)) else: print(Renaming {!r} to {!r}.format(old_path, new_path)) os.rename(old_path, new_path) -- http://mail.python.org/mailman/listinfo/python-list
Mistakes in documentation
Where can I submit little mistakes in Python documantation? I found one while browsing tutorial.pdf (Python 3.3.2): Section 3.1 says (on page 12): word[2:5] # characters from position 2 (included) to 4 (excluded) ’tho’ Shouldn't the comment say 5 (excluded) or 4 (included) instead? -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
First of all thank you for helping me MRAB. After make some alternation to your code ia have this: # Give the path as a bytestring so that we'll get the filenames as bytestrings path = b/home/nikos/public_html/data/apps/ # Setting TESTING to True will make it print out what renamings it will do, but not actually do them TESTING = True # Walk through the files. for root, dirs, files in os.walk( path ): for filename in files: try: # Is this name encoded in UTF-8? filename.decode('utf-8') except UnicodeDecodeError: # Decoding from UTF-8 failed, which means that the name is not valid UTF-8 # It appears that the filenames are encoded in ISO-8859-7, so decode from that and re-encode to UTF-8 new_filename = filename.decode('iso-8859-7').encode('utf-8') old_path = os.path.join(root, filename) new_path = os.path.join(root, new_filename) if TESTING: print( '''brWill rename {!r} --- {!r}brbr'''.format( old_path, new_path ) ) else: print( '''brRenaming {!r} --- {!r}brbr'''.format( old_path, new_path ) ) os.rename( old_path, new_path ) sys.exit(0) - and the output can be seen here: http://superhost.gr/cgi-bin/files.py We are in test mode so i dont know if when renaming actually take place what the encodings will be. Shall i switch off test mode and try it for real? -- http://mail.python.org/mailman/listinfo/python-list
Re: How to store a variable when a script is executing for next time execution?
Thanks. On Thu, Jun 6, 2013 at 4:49 PM, Cameron Simpson c...@zip.com.au wrote: On 06Jun2013 03:50, Avnesh Shakya avnesh.n...@gmail.com wrote: | hi, |I am running a python script and it will create a file name like filename0.0.0 and If I run it again then new file will create one more like filename0.0.1.. my code is- | | i = 0 | for i in range(1000): | try: | with open('filename%d.%d.%d.json'%(0,0,i,)): pass | continue | except IOError: | dataFile = file('filename%d.%d.%d.json'%(0,0,i,), 'a+') | break | But It will take more time after creating many files, So i want to store value of last var i in a variable so that when i run my script again then I can use it. for example- | my last created file is filename0.0.27 then it should store 27 in a variable and when i run again then new file should be created 0.0.28 according to last value 27, so that i could save time and it can create file fast.. | | Please give me suggestion for it.. How is it possible? Write it to a file? Read the file next time the script runs? BTW, trying to open zillions of files is slow. But using listdir to read the directory you can see all the names. Pick the next free one (and then test anyway). -- Cameron Simpson c...@zip.com.au The mark must be robust enough to survive MP3 transmission over the Internet, but remain inaudible when played on the yet to be launched DVD-Audio players. - the SDMI audio watermarkers literally ask for the impossible, since all audio compressors aim to pass _only_ human perceptible data http://www.newscientist.com/news/news.jsp?id=ns224836 -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: How to store a variable when a script is executing for next time execution?
On 06/06/2013 06:50 AM, Avnesh Shakya wrote: hi, I am running a python script and it will create a file name like filename0.0.0 and If I run it again then new file will create one more like filename0.0.1.. my code is- i = 0 Redundant initialization of i. for i in range(1000): try: with open('filename%d.%d.%d.json'%(0,0,i,)): pass continue except IOError: dataFile = file('filename%d.%d.%d.json'%(0,0,i,), 'a+') break But It will take more time after creating many files, So i want to store value of last var i in a variable There are no variables once the program ends. You mean you want to store it in the file. That's known as persistent storage, and in the general case you could use pickle or something like that. But in your simple case, the easiest thing would be to simply write the last value of i out to a file in the same directory. Then when your program starts, it opens that extra file and reads in the value of i. And uses that for the starting value in the loop. so that when i run my script again then I can use it. for example- my last created file is filename0.0.27 then it should store 27 in a variable and when i run again then new file should be created 0.0.28 according to last value 27, so that i could save time and it can create file fast.. Please give me suggestion for it.. How is it possible? Thanks Incidentally, instead of opening each one, why not check its existence? Should be quicker, and definitely clearer. Entirely separate suggestion, since I dislike having extra housekeeping files that aren't logically necessary, and that might become out of synch : If you're planning on having the files densely populated (meaning no gaps in the numbering), then you could use a binary search to find the last one. Standard algorithm would converge with 10 existence checks if you have a limit of 1000 files. -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Mistakes in documentation
06.06.13 15:01, Paul Volkov написав(ла): Where can I submit little mistakes in Python documantation? http://bugs.python.org/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
On Tue, 04 Jun 2013 02:00:43 -0700, Νικόλαος Κούρας wrote: Τη Τρίτη, 4 Ιουνίου 2013 11:47:01 π.μ. UTC+3, ο χρήστης Steven D'Aprano έγραψε: Please run these commands, and show what result they give: [...] ni...@superhost.gr [~/www/data/apps]# alias ls alias ls='/bin/ls $LS_OPTIONS' And what does echo $LS_OPTIONS give? [...] Seems that the way the system used to actually rename the file matters. Yes. This is where you get interactions between different systems that use different encodings, and they don't work well together. Some day, everything will use UTF-8, and these problems will go away. If all else fails, you could just rename the troublesome file and hopefully the problem will go away: mv *Ο.mp3 1.mp3 mv 1.mp3 Eυχή του Ιησού.mp3 Yes, but why you are doing it it 2 steps and not as: mv *Ο.mp3 'Eυχή του Ιησού.mp3' I don't remember. I had a reason that made sense at the time, but I can't remember what it was. I think I can reproduce your problem. If I open a terminal, set to use UTF-8, I can do this: [steve@ando ~]$ cd /tmp [steve@ando tmp]$ touch '999-Eυχή-του-Ιησού' [steve@ando tmp]$ ls 999* 999-Eυχή-του-Ιησού Now if I change the terminal to use Greek ISO-8859-7, and hit UP-ARROW to grab the previous command line from history, the *displayed* file name changes, but the actual file being touched remains the same: [steve@ando tmp]$ touch '999-EΟΟΞ�-ΟΞΏΟ-ΞΞ·ΟΞΏΟ' [steve@ando tmp]$ ls 999* 999-EΟΟΞ�-ΟΞΏΟ-ΞΞ·ΟΞΏΟ In Python 3.3, I can demonstrate the same sort of thing: py s = '999-Eυχή-του-Ιησού' py bytes_as_utf8 = s.encode('utf-8') py t = bytes_as_utf8.decode('iso-8859-7', errors='replace') py print(t) 999-EΟΟΞ�-ΟΞΏΟ-ΞΞ·ΟΞΏΟ So that demonstrates part of your problem: even though your Linux system is using UTF-8, your terminal is probably set to ISO-8859-7. The interaction between these will lead to strange and disturbing Unicode errors. To continue, back in the terminal set to ISO-8859-7, if instead of using the history line, if I re-copy and paste the file name: [steve@ando tmp]$ touch '999-Eυχή-του-Ιησού' [steve@ando tmp]$ ls 999* 999-E???-???-? 999-EΟΟΞ�-ΟΞΏΟ-ΞΞ·ΟΞΏΟ So now I end up with two files, one with a file name that is utter garbage bytes, and one that is only a little better, being mojibake. Resetting the terminal to use UTF-8 at least now restores the *display* of the earlier file's name: [steve@ando tmp]$ ls 999* 999-E???-???-? 999-Eυχή-του-Ιησού [steve@ando tmp]$ ls -b 999* 999-E\365\367\336-\364\357\365-\311\347\363\357\375 999-Eυχή-του-Ιησού but the other file name is still made of garbage bytes. So I believe I understand how your file name has become garbage. To fix it, make sure that your terminal is set to use UTF-8, and then rename it. Do the same with every file in the directory until the problem goes away. (If one file has garbage bytes in the file name, chances are that more than one do.) -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: How to store a variable when a script is executing for next time execution?
Avnesh Shakya writes: I am running a python script and it will create a file name like filename0.0.0 and If I run it again then new file will create one more like filename0.0.1.. my code is- i = 0 for i in range(1000): try: with open('filename%d.%d.%d.json'%(0,0,i,)): pass continue except IOError: dataFile = file('filename%d.%d.%d.json'%(0,0,i,), 'a+') break But It will take more time after creating many files, So i want to store value of last var i in a variable so that when i run my script again then I can use it. for example- my last created file is filename0.0.27 then it should store 27 in a variable and when i run again then new file should be created 0.0.28 according to last value 27, so that i could save time and it can create file fast.. You could get a list of all filenames that match the pattern. Extract the last components as numbers, and add 1 to the maximum. i = 1 + max(int(name.split('.')[-1]) for name in glob.glob('filename.0.0.*)) That assumes that there already is at least one such file and all such files have a last component that can be parsed as an int. Take an appropriate amount of care. Or you could also create a file, say lastname.0.0.31, to track the name, and when you find it there, create filename.0.0.32 and replace lastname.0.0.32; panic if there is more than one lastname.0.0.*, or fewer than one. Or as above but track with nextname.0.0.31 to create filename.0.0.31 and replace the tracking name with nextname.0.0.32 for the next file. Or save the number somewhere else. -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
On 06/06/2013 13:04, Νικόλαος Κούρας wrote: First of all thank you for helping me MRAB. After make some alternation to your code ia have this: # Give the path as a bytestring so that we'll get the filenames as bytestrings path = b/home/nikos/public_html/data/apps/ # Setting TESTING to True will make it print out what renamings it will do, but not actually do them TESTING = True # Walk through the files. for root, dirs, files in os.walk( path ): for filename in files: try: # Is this name encoded in UTF-8? filename.decode('utf-8') except UnicodeDecodeError: # Decoding from UTF-8 failed, which means that the name is not valid UTF-8 # It appears that the filenames are encoded in ISO-8859-7, so decode from that and re-encode to UTF-8 new_filename = filename.decode('iso-8859-7').encode('utf-8') old_path = os.path.join(root, filename) new_path = os.path.join(root, new_filename) if TESTING: print( '''brWill rename {!r} --- {!r}brbr'''.format( old_path, new_path ) ) else: print( '''brRenaming {!r} --- {!r}brbr'''.format( old_path, new_path ) ) os.rename( old_path, new_path ) sys.exit(0) - and the output can be seen here: http://superhost.gr/cgi-bin/files.py We are in test mode so i dont know if when renaming actually take place what the encodings will be. Shall i switch off test mode and try it for real? The first one is '/home/nikos/public_html/data/apps/Ευχή του Ιησού.mp3'. The second one is '/home/nikos/public_html/data/apps/Σκέψου έναν αριθμό.exe'. These names are currently encoded in ISO-8859-7, but will be encoded in UTF-8 if you turn off test mode. If you're happy for that change to happen, then go ahead. -- http://mail.python.org/mailman/listinfo/python-list
Re: Mistakes in documentation
On 6/6/2013 8:01 AM, Paul Volkov wrote: Where can I submit little mistakes in Python documantation? I found one while browsing tutorial.pdf (Python 3.3.2): Section 3.1 says (on page 12): word[2:5] # characters from position 2 (included) to 4 (excluded) ’tho’ Shouldn't the comment say 5 (excluded) or 4 (included) instead? At the bottom of the index page, in the Meta information section, is an entry for the Reporting bugs doc. It says to email d...@python.org or to use the tracker for a persistent record. This is followed by an explanation of using the tracker. Terry -- http://mail.python.org/mailman/listinfo/python-list
Re: Bools and explicitness [was Re: PyWart: The problem with print]
On Jun 6, 6:45 am, Chris Angelico ros...@gmail.com wrote: On Thu, Jun 6, 2013 at 11:37 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: What prevents bugs is the skill of the people writing the code, not the compiler. +1 QOTW. In many Indian languages there is a saying: A poor dancer blames the crooked floor. [Yeah… sounds tame in English] -- which is probably what Steven is saying. However in defence of the crooked floor… wink When I taught C at the university in the early 90s[1], every third/ fourth compile+run of the kids would result in 'segmentation fault' if they were lucky enough to be on unix, and OS crashes if they were on DOS. At first I would rail at the kids for not doing due diligence. Over time I came to the conclusion that if a system is designed in such a way that everyone is wrong, then its the system that is wrong and not everyone. When we switched from to python (via Scheme and a haskell- predecessor), I dont remember ever getting a segmentation fault. [Well once RR gave some Wx code that I tried and python core dumped. Whether this speaks for RR or Wx or a dangerous combo...] So yes, elegant programming languages are not proof against inelegant programmers. Nevertheless, programming languages can be made in a way that makes certain class of errors harder/easier to make. Joel Spolsky moans that: Java is not, generally, a hard enough programming language that it can be used to discriminate between great programmers and mediocre programmers. http://www.joelonsoftware.com/articles/ThePerilsofJavaSchools.html And Paul Graham is even more provocative: Java programmers are not as smart as python programmers http://www.paulgraham.com/gh.html [1] Prompted a paper in the 90s, with some modernizing modifications http://blog.languager.org/2013/02/c-in-education-and-software-engineering.html -- http://mail.python.org/mailman/listinfo/python-list
Re: I just wrote my first Python program a guessing game and it exits with an error I get this.
Yes Steven a C book I am reading has a quote Every programmer is fluent in swearing After my blow ups and confusion I am happy with my program anyway. I will get better at it eventually. I did change things to raw_input and works fine. -- http://mail.python.org/mailman/listinfo/python-list
Re: Bools and explicitness [was Re: PyWart: The problem with print]
On Fri, Jun 7, 2013 at 12:09 AM, rusi rustompm...@gmail.com wrote: When we switched from to python (via Scheme and a haskell- predecessor), I dont remember ever getting a segmentation fault. Oh, it's easy to segfault Python. import sys sys.setrecursionlimit(9) def foo(): foo() foo() :) ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Bools and explicitness [was Re: PyWart: The problem with print]
On 2013-06-06 10:45, Chris Angelico wrote: For the accept any object that has a next() method sorts of rules, I don't know of any really viable system that does that usefully. The concept of implementing interfaces in Java comes close, but the class author has to declare that it's implementing some named interface. In theory there could be something that deduces the validity from the given structure, but I'm not aware of any language that does this. But it would let you do stuff like this (prototyped in Python): class Integers: def __init__(self): self.value=0 def next(self): self.value+=1 return self.value interface Iterable: next(self) def grab_three_values(Iterable iter): return iter.next(),iter.next(),iter.next() With a language that checks these sorts of things at compile time, it's not a big deal to test. With something fully dynamic like Python, it's probably not worth the effort. But maybe checks like this could be useful to something like Coverity. As Serhiy notes, Go does this, almost exactly as you wrote it (modulo syntax). http://golang.org/doc/effective_go.html#interfaces_and_types -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: How to store a variable when a script is executing for next time execution?
On Thu, Jun 6, 2013 at 10:14 PM, Dave Angel da...@davea.name wrote: If you're planning on having the files densely populated (meaning no gaps in the numbering), then you could use a binary search to find the last one. Standard algorithm would converge with 10 existence checks if you have a limit of 1000 files. Or, if you can dedicate a directory to those files, you could go even simpler: dataFile = open('filename0.0.%d.json'%len(os.listdir()), 'w') The number of files currently existing equals the number of the next file. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Bools and explicitness [was Re: PyWart: The problem with print]
On Jun 6, 8:26 pm, Chris Angelico ros...@gmail.com wrote: On Fri, Jun 7, 2013 at 12:09 AM, rusi rustompm...@gmail.com wrote: When we switched from to python (via Scheme and a haskell- predecessor), I dont remember ever getting a segmentation fault. Oh, it's easy to segfault Python. import sys sys.setrecursionlimit(9) def foo(): foo() foo() :) ChrisA And so you are hereby anointed into the august company of RR!! -- http://mail.python.org/mailman/listinfo/python-list
Re: Bools and explicitness [was Re: PyWart: The problem with print]
On Fri, Jun 7, 2013 at 1:36 AM, rusi rustompm...@gmail.com wrote: On Jun 6, 8:26 pm, Chris Angelico ros...@gmail.com wrote: On Fri, Jun 7, 2013 at 12:09 AM, rusi rustompm...@gmail.com wrote: When we switched from to python (via Scheme and a haskell- predecessor), I dont remember ever getting a segmentation fault. Oh, it's easy to segfault Python. import sys sys.setrecursionlimit(9) def foo(): foo() foo() :) ChrisA And so you are hereby anointed into the august company of RR!! Eh? No, I'm just adept at breaking stuff... I could probably segfault a 100Mbit switch if I tried (or just got careless). ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Bools and explicitness [was Re: PyWart: The problem with print]
On Fri, Jun 7, 2013 at 1:35 AM, Robert Kern robert.k...@gmail.com wrote: On 2013-06-06 10:45, Chris Angelico wrote: For the accept any object that has a next() method sorts of rules, I don't know of any really viable system that does that usefully. The concept of implementing interfaces in Java comes close, but the class author has to declare that it's implementing some named interface. In theory there could be something that deduces the validity from the given structure, but I'm not aware of any language that does this. But it would let you do stuff like this (prototyped in Python): As Serhiy notes, Go does this, almost exactly as you wrote it (modulo syntax). http://golang.org/doc/effective_go.html#interfaces_and_types Thanks (and thanks for actually providing a link). Many years ago I came to the conclusion that anything I could conceive in language design has already been done somewhere :) Anyway, regardless of your language, there's always some criteria that can't be coded. Suppose the valid input for a function were integers whose square roots are integers but whose cube roots are not. You won't easily get compile-time checking of that. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: How to store a variable when a script is executing for next time execution?
On 06/06/2013 16:37, Chris Angelico wrote: On Thu, Jun 6, 2013 at 10:14 PM, Dave Angel da...@davea.name wrote: If you're planning on having the files densely populated (meaning no gaps in the numbering), then you could use a binary search to find the last one. Standard algorithm would converge with 10 existence checks if you have a limit of 1000 files. Or, if you can dedicate a directory to those files, you could go even simpler: dataFile = open('filename0.0.%d.json'%len(os.listdir()), 'w') The number of files currently existing equals the number of the next file. Assuming no gaps. -- http://mail.python.org/mailman/listinfo/python-list
Re: Bools and explicitness [was Re: PyWart: The problem with print]
On Wednesday, June 5, 2013 11:59:07 AM UTC-5, Chris Angelico wrote: Frankly, I don't think the language much matters. It's all down to the skill of the programmers and testers. Ada wasn't the source of the problem unless Ada has a bug in it... which is going to be true of pretty much any language. Maybe Python would be a better choice, maybe not; but let me tell you this, if the choice of language means the difference between testable in three months and testable code in three years, I'm going for the former. Yes EVEN IF life or property hangs in the balance, the only important decision is how much work YOU will be required to do -- Chris, why i am not amazed by this bombastic display of selfishness? -- http://mail.python.org/mailman/listinfo/python-list
Re: How to store a variable when a script is executing for next time execution?
On Fri, Jun 7, 2013 at 1:54 AM, MRAB pyt...@mrabarnett.plus.com wrote: On 06/06/2013 16:37, Chris Angelico wrote: On Thu, Jun 6, 2013 at 10:14 PM, Dave Angel da...@davea.name wrote: If you're planning on having the files densely populated (meaning no gaps in the numbering), then you could use a binary search to find the last one. Standard algorithm would converge with 10 existence checks if you have a limit of 1000 files. Or, if you can dedicate a directory to those files, you could go even simpler: dataFile = open('filename0.0.%d.json'%len(os.listdir()), 'w') The number of files currently existing equals the number of the next file. Assuming no gaps. Which is also a stated assumption of the binary search. The only additional assumption of the file-count method is that there be no other files in that directory. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Bools and explicitness [was Re: PyWart: The problem with print]
On Fri, Jun 7, 2013 at 1:49 AM, Rick Johnson rantingrickjohn...@gmail.com wrote: On Wednesday, June 5, 2013 11:59:07 AM UTC-5, Chris Angelico wrote: Frankly, I don't think the language much matters. It's all down to the skill of the programmers and testers. Ada wasn't the source of the problem unless Ada has a bug in it... which is going to be true of pretty much any language. Maybe Python would be a better choice, maybe not; but let me tell you this, if the choice of language means the difference between testable in three months and testable code in three years, I'm going for the former. Yes EVEN IF life or property hangs in the balance, the only important decision is how much work YOU will be required to do -- Chris, why i am not amazed by this bombastic display of selfishness? I would like to say that you're not amazed because you're intelligent enough to understand what I was saying, but I'm not sure it'd be true. Let me spell it out for you. * Deadlines are real things. They make a very audible whooosh as they go past. * If the time frame for developing this is five years, then in five years, the code must either be shipped or scrapped. * Taking three years to get to a testable codebase allows two years to test. * Taking three months to get testable allows over four years to test. Would you say that doubling the testing period is a good thing or a bad thing? ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Bools and explicitness [was Re: PyWart: The problem with print]
On 2013-06-06 16:41, Chris Angelico wrote: Anyway, regardless of your language, there's always some criteria that can't be coded. Suppose the valid input for a function were integers whose square roots are integers but whose cube roots are not. You won't easily get compile-time checking of that. Say that on a Haskell list, and they'll take it as a challenge. :-) -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: Bools and explicitness [was Re: PyWart: The problem with print]
On Wednesday, June 5, 2013 6:18:13 PM UTC-5, Michael Torrie wrote: On 06/05/2013 12:11 AM, Russ P. wrote: But then, what would you expect of a language that allows you to write x = 1 x = Hello It's all loosey goosey -- which is fine for many applications but certainly not for critical ones. This comment shows me that you don't understand the difference between names, objects, and variables. May sound like a minor quibble, but there're actually major differences between binding names to objects (which is what python does) and variables (which is what languages like C have). It's very clear Rick does not have an understanding of this either. Just because someone does not prefer this or that aspect of Python, does not mean they don't understand it. I understand implicit conversion to Boolean just fine, however, i don't like it. Actually, i hate it! I think it's foolish. It was invented by people who rather save a few keystrokes at the cost writing cryptic code. There are many good reasons for saving keystrokes, implicit conversion to Boolean is NOT one of them. I make the same argument for return. Some languages allow implicit return values from functions/methods. When writing a function with Ruby, the return statement is optional: ## START RUBY CODE ## def foo: implicit return end rb puts foo implicit return ## END RUBY CODE ## This is one area where Python shines! In Python, if you fail to use the return statement, then Python will return None, NOT some some value that just happens to be the last line executed in the function -- Ruby breaks the law of least astonishment. The point is we must balance our selfish need to save keystrokes against the need of a reader to QUICKLY understand what he is reading. Python's explicit return statement satisfies both requirements, whereas, the optional return value of Ruby does not. We don't want to overly implicit, or overly explicit (as in the nightmare of public static void foo, which is overkill (at least for a language as high level as Python)). -- http://mail.python.org/mailman/listinfo/python-list
Re: Bools and explicitness [was Re: PyWart: The problem with print]
On Thu, Jun 6, 2013 at 12:24 PM, Rick Johnson rantingrickjohn...@gmail.com wrote: In Python, if you fail to use the return statement, then Python will return None, NOT some some value that just happens to be the last line executed in the function -- Ruby breaks the law of least astonishment. Ruby comes from a tradition where this behavior is not astonishing. Languages do not exist in a vacuum. -- Devin -- http://mail.python.org/mailman/listinfo/python-list
Re: Bools and explicitness [was Re: PyWart: The problem with print]
On Wednesday, June 5, 2013 2:15:57 AM UTC-5, Chris Angelico wrote: [...] I cannot name a single modern programming language that does NOT have some kind of implicit boolification. Congrats: Again you join the ranks of most children who make excuses for their foolish actions along the lines of: Hey, they did it first! Well, the lemmings get what they deserve i suppose. -- http://mail.python.org/mailman/listinfo/python-list
Thread-safe way to prevent decorator from being nested
I'm writing a decorator that I never want to be nested. Following from the answer on my StackOverflow question (http://stackoverflow.com/a/16905779/106244), I've adapted it to the following. Can anyone spot any issues with this? It'll be run in a multi-threaded environment serving Django requests and also be a part of Celery tasks. import threading from contextlib import contextmanager from functools import wraps thread_safe_globals = threading.local() @contextmanager def flag(): thread_safe_globals._within_special_context = True try: yield finally: thread_safe_globals._within_special_context = False def within_special_wrapper(): try: return thread_safe_globals._within_special_context except AttributeError: return False def my_special_wrapper(f): @wraps(f) def internal(*args, **kwargs): if not within_special_wrapper(): with flag(): f(*args, **kwargs) else: raise Exception(No nested calls!) return internal @my_special_wrapper def foo(): print(within_special_wrapper()) bar() print('Success!') @my_special_wrapper def bar(): pass foo() -- http://mail.python.org/mailman/listinfo/python-list
Re: Bools and explicitness [was Re: PyWart: The problem with print]
On Fri, Jun 7, 2013 at 2:49 AM, Rick Johnson rantingrickjohn...@gmail.com wrote: On Wednesday, June 5, 2013 2:15:57 AM UTC-5, Chris Angelico wrote: [...] I cannot name a single modern programming language that does NOT have some kind of implicit boolification. Congrats: Again you join the ranks of most children who make excuses for their foolish actions along the lines of: Hey, they did it first! Well, the lemmings get what they deserve i suppose. You say that like it's a bad thing. http://www.catb.org/jargon/html/E/ELIZA-effect.html ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Bools and explicitness [was Re: PyWart: The problem with print]
On Jun 6, 9:08 pm, Robert Kern robert.k...@gmail.com wrote: On 2013-06-06 16:41, Chris Angelico wrote: Anyway, regardless of your language, there's always some criteria that can't be coded. Suppose the valid input for a function were integers whose square roots are integers but whose cube roots are not. You won't easily get compile-time checking of that. Say that on a Haskell list, and they'll take it as a challenge. :-) Yes, all programming communities have blind-spots. The Haskell community's is that Haskell is safe and safe means that errors are caught at compile-time. Unfortunately* the halting problem stands. When generalized to Rice theorem it says that only trivial properties of programs are algorithmically decidable: http://mathworld.wolfram.com/RicesTheorem.html And so the semantic correctness of a program -- a non-trivial property -- is not decidable. In short the Haskell dream is a pipe-dream**. Discussed in more detail here: http://blog.languager.org/2012/08/functional-programming-philosophical.html. Nevertheless I need to say: If a programmers comes to python from Haskell, he will end up being a better programmer than one coming from C or Java or… * actually fortunately considering that for most of us programming is our job :-) ** Haskellers would point out that there is agda which grows out of Haskell and in agda one can encode arbitrary properties of types. -- http://mail.python.org/mailman/listinfo/python-list
Re: Bools and explicitness [was Re: PyWart: The problem with print]
On 2013-06-06, Chris Angelico ros...@gmail.com wrote: Would you say that doubling the testing period is a good thing or a bad thing? It could be a neutral thing (ignoring the costs involved). I once read read an article claiming that as you test (and fix) any large, complex piece of software, you asymptotically approach a certain fixed minimum number of bugs that's determined by the system's overall architecture, design and implentation. Once you get sufficiently close to that minimum, additional testing doesn't reduce the number/severity of bugs -- it just moves them around by creating additional bugs at the same rate you are eliminating old ones. When you get to that point, the only way to significantly improve the situation is to toss the whole thing out and start over with a better system architecture and/or development model. After having maintined a few largish pieces of software for well over a decade, I'm fairly convinced that's true -- especially if you also consider post-deployment maintenance (since at that point you're usually also trying to add features at the same time you're fixing bugs). -- Grant Edwards grant.b.edwardsYow! I just went below the at poverty line! gmail.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Bools and explicitness [was Re: PyWart: The problem with print]
Whatever benefit there is in declaring the type of a function is lost due to the inability to duck-type or program to an interface. There's no type that says any object with a 'next' method, for example. And having to declare local variables is a PITA with little benefit. Give me a language with type inference, and a nice, easy way to keep duck- typing, and I'll reconsider. But until then, I don't believe the benefit of static types comes even close to paying for the extra effort. Okay, I'm going straighten out you foo(l)s once and for all. Python has seduced us all into lazy typing. That's what it is. Manual type checking is obviously inferior to compiler type-checking. This is what I was trying to tell you all with the post of re-vamping the Object model. Python, and I along with it, went towards this idea of a grand god Object that is the father of everything, but it turned out to be the wrong direction. Refer to my post on OOPv2. The fact is, that none of us is close enough to God and the programming art isn't evolved enough to try to accomplish some grand generic object at the top of the ObjectModel. It just isn't. We were better off closer to the machine. Automatic conversion from int to long was good enough. -- MarkJ Tacoma, Washington P.S. See also PythonThreeThousand on wikiwikiweb http://c2.com/cgi/wiki?WikiWikiWeb -- http://mail.python.org/mailman/listinfo/python-list
Re: Apache and suexec issue that wont let me run my python script
On 06/05/2013 08:02 PM, Tim Chase wrote: On 2013-06-05 17:57, ru...@yahoo.com wrote: stories over the years where people where convicted (or at least charged with) violating the DMCA (or perhaps equally draconian followup U.S. laws) even though they clearly penetrated the system to point out security flaws. I suspect you read CFAA (Computer Fraud Abuse Act) and thought DMCA (Digital Millennium Copyright Act), as there have been a number of prosecutions under the CFAA (including the whole Aaron Swartz ordeal) for nebulous exceeding authorization/ Yes, thanks for correcting that. -- http://mail.python.org/mailman/listinfo/python-list
Re: Bools and explicitness [was Re: PyWart: The problem with print]
On Wednesday, June 5, 2013 8:37:20 PM UTC-5, Steven D'Aprano wrote: On Wed, 05 Jun 2013 09:15:01 -0700, Russ P. wrote: On Wednesday, June 5, 2013 1:59:01 AM UTC-7, Mark Lawrence wrote: On 05/06/2013 07:11, Russ P. wrote: What prevents bugs is the skill of the people writing the code, not the compiler. Compile-time static type checking is merely a tool, which has costs and benefits. It is ludicrous to think that any one single tool, or the lack of that tool, will make all the difference between working code and non-working code. Yes, just as ludicrous as thinking that dynamic languages have abolished the evil practice of type checking. Static type-checking is no better, or worse, for critical code than dynamic type-checking. One language chooses to deal with some errors at compile-time, others deal with them at run-time. Wow, talk about ignoring the elephant in the room! I don't feel i need static typed languages for EVERY problem, however, i'm not foolish enough to believe that compile time type checking and run-time type checking are even comparable. Oversimplification? Either way, the programmer has to deal with them in some way. A static type system forces you to deal with a limited subset of errors, type errors, in one way only: by removing any execution paths in the software which would assign data of type X to a variable of type Y. For reasons of machine efficiency, that is often a good was to deal with such errors. But a dynamic type system makes different trade-offs. And of course, type errors are such a vanishingly small subset of all the possible errors that might be made that, frankly, the difference in code quality between those with static typing and those without is essentially indistinguishable. There's no evidence that code written in static typed languages is less buggy than code written in dynamic languages. WOW! Your skill with the implicit Ad hominem is approaching guru status. First you cleverly convert the base argument of this ongoing discussion from: implicit conversion to boolean is bad, into the hot button topic of: static vs dynamic typing. In this manner you can ratchet up the emotion of your supporters by employing the same political slight of hand used by countless political hacks: Liberal vs Republican ring a bell? When there is only two choices, the sheeple can be easily manipulated by the football game. Especially when the opposing sides have the same end-goal in mind. It's all a game of diversions you idiots! Then you go and make a blanket statement that appears to weigh the differences of the two styles fairly, when in fact, what you've done is to falsely invalidate the opposition's entire argument based on a complete overstatement (not to mention that you stopped short of explaining the trade offs in detail): And of course, type errors are such a vanishingly small subset of all the possible errors that might be made that, frankly, the difference in code quality between those with static typing and those without is essentially indistinguishable. Nice! Well, then. You've slayed the enemy. If type errors are as rare as you claim, then by golly these crazy people who use static languages are really just fools. I mean, how could they not be? If they were as intelligent as YOU then they would see the truth! Your attempts at sleight of hand are rather amusing. The whole point of this implicit conversion to Boolean discussion hinges around the fact that dynamic languages are okay for small to medium problems ( or for prototyping larger problems). But they cannot be depended on for mission critical code. And mission critical does not only encompass manned flights to mars, it could be any code that places your reputation on the line. I don't want Python to be a static typed language. Neither do i believe that duck typing is wrong for Python. HOWEVER, what i DO believe is that dynamic languages can be unreliable if we do not: 1. Choose to be explicit enough I've explained this in detail Ad-nauseam. 2. Fail to type check where type checking is due. The second covers type checking objects that enter into new namespaces. That would cover all functions/methods arguments (at a minimum). We don't need to type check EVERY single object (but of course the programmer could IF he wanted to). If i declare a variable[1] that points to a list in a block of code, then i reference that variable[1] in the same block of code, i see no reason to type check that variable[1] first. That is overkill and that is why people are turned off by static languages. However, if i declare the same variable[1] and then pass that variable[1] into a function, the function should do a type check on all the arguments to guarantee that these arguments are in fact what they should be. This is how you strike a balance between explicit and implicit. This is how you inject sanity into your code
Re: Bools and explicitness [was Re: PyWart: The problem with print]
On Thursday, June 6, 2013 2:29:02 AM UTC-7, Steven D'Aprano wrote: On Thu, 06 Jun 2013 12:29:44 +1000, Chris Angelico wrote: On Thu, Jun 6, 2013 at 11:56 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Wed, 05 Jun 2013 14:59:31 -0700, Russ P. wrote: As for Python, my experience with it is that, as your application grows, you start getting confused about what the argument types are or are supposed to be. Whereas people never get confused about the arguments in static typed languages? The only difference is whether the compiler tells you that you've passed the wrong type, or your unit test tells you that you've passed the wrong type. What, you don't have unit tests? Then how do you know that the code does the right thing when passed data of the right type? Adding an extra couple of unit tests is not that big a burden. The valid type(s) for an argument can be divided into two categories: Those the compiler can check for, and those the compiler can't check for. Some languages have more in the first category than others, but what compiler can prove that a string is an HTML-special-characters-escaped string? In a very few languages, the compiler can insist that an integer be between 7 and 30, but there'll always be some things you can't demonstrate with a function signature. That said, though, I do like being able to make at least *some* declaration there. It helps catch certain types of error. *shrug* I don't terribly miss type declarations. Function argument declarations are a bit simpler in Pascal, compared to Python: Function Add(A, B : Integer) : Integer; Begin Add := A + B; End; versus def add(a, b): if not (isinstance(a, int) and isinstance(b, int)): raise TypeError return a + b Scala also has isInstanceOf[Type] which allows you to do this sort of thing, but of course it would be considered terrible style in Scala. but not that much simpler. And while Python can trivially support multiple types, Pascal cannot. (Some other static typed languages may.) Whatever benefit there is in declaring the type of a function is lost due to the inability to duck-type or program to an interface. There's no type that says any object with a 'next' method, for example. And having to declare local variables is a PITA with little benefit. Give me a language with type inference, and a nice, easy way to keep duck- typing, and I'll reconsider. But until then, I don't believe the benefit of static types comes even close to paying for the extra effort. Scala has type inference. For example, you can write val x = 1 and the compiler figures out that x is an integer. Scala also has something called structural typing, which I think is more or less equivalent to duck typing, although I don't think it is used very often. Are you ready to try Scala yet? 8-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Bools and explicitness [was Re: PyWart: The problem with print]
On Thursday, June 6, 2013 1:03:24 PM UTC-5, Rick Johnson wrote: The second covers type checking objects that enter into new namespaces. That would cover all functions/methods arguments (at a minimum). Yeah, before anyone starts complaining about this, i meant to say scope. Now you can focus on the *real* argument instead of spending all your time pointing out minutiae. -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
Τη Πέμπτη, 6 Ιουνίου 2013 3:50:52 μ.μ. UTC+3, ο χρήστης MRAB έγραψε: If you're happy for that change to happen, then go ahead. I have made some modifications to the code you provided me but i think something that doesnt accur to me needs fixing. for example i switched: # Give the path as a bytestring so that we'll get the filenames as bytestrings path = b/home/nikos/public_html/data/apps/ # Walk through the files. for root, dirs, files in os.walk( path ): for filename in files: to: # Give the path as a bytestring so that we'll get the filenames as bytestrings path = os.listdir( b'/home/nikos/public_html/data/apps/' ) # iterate over all filenames in the apps directory for fullpath in path # Grabbing just the filename from path filename = fullpath.replace( '/home/nikos/public_html/data/apps/', '' ) I dont know if it has the same effect: Here is the the whole snippet: = # Give the path as a bytestring so that we'll get the filenames as bytestrings path = os.listdir( b'/home/nikos/public_html/data/apps/' ) # iterate over all filenames in the apps directory for fullpath in path # Grabbing just the filename from path filename = fullpath.replace( '/home/nikos/public_html/data/apps/', '' ) try: # Is this name encoded in utf-8? filename.decode('utf-8') except UnicodeDecodeError: # Decoding from UTF-8 failed, which means that the name is not valid utf-8 # It appears that this filename is encoded in greek-iso, so decode from that and re-encode to utf-8 new_filename = filename.decode('iso-8859-7').encode('utf-8') # rename filename form greek bytestream- utf-8 bytestream old_path = os.path.join(root, filename) new_path = os.path.join(root, new_filename) os.rename( old_path, new_path ) # # Compute a set of current fullpaths path = os.listdir( '/home/nikos/public_html/data/apps/' ) # Load'em for fullpath in path: try: # Check the presence of a file against the database and insert if it doesn't exist cur.execute('''SELECT url FROM files WHERE url = %s''', (fullpath,) ) data = cur.fetchone()#URL is unique, so should only be one if not data: # First time for file; primary key is automatic, hit is defaulted cur.execute('''INSERT INTO files (url, host, lastvisit) VALUES (%s, %s, %s)''', (fullpath, host, lastvisit) ) except pymysql.ProgrammingError as e: print( repr(e) ) == The error is: [Thu Jun 06 21:10:23 2013] [error] [client 79.103.41.173] File files.py, line 64 [Thu Jun 06 21:10:23 2013] [error] [client 79.103.41.173] for fullpath in path [Thu Jun 06 21:10:23 2013] [error] [client 79.103.41.173] ^ [Thu Jun 06 21:10:23 2013] [error] [client 79.103.41.173] SyntaxError: invalid syntax Doesn't os.listdir( ...) returns a list with all filenames? But then again when replacing take place to shert the fullpath to just the filane i think it doesn't not work because the os.listdir was opened as bytestring and not as a string What am i doing wrong? -- http://mail.python.org/mailman/listinfo/python-list
Re: Bools and explicitness [was Re: PyWart: The problem with print]
Super OT divergence because I am a loser nerd: On Thu, Jun 6, 2013 at 1:27 PM, rusi rustompm...@gmail.com wrote: Yes, all programming communities have blind-spots. The Haskell community's is that Haskell is safe and safe means that errors are caught at compile-time. I don't think Haskell people believe this with the thoroughness you describe. There are certainly haskell programmers that are aware of basic theory of computation. Unfortunately* the halting problem stands. When generalized to Rice theorem it says that only trivial properties of programs are algorithmically decidable: http://mathworld.wolfram.com/RicesTheorem.html And so the semantic correctness of a program -- a non-trivial property -- is not decidable. Just because a problem is NP-complete or undecidable, doesn't mean there aren't techniques that give the benefits you want (decidability, poly-time) for a related problem. Programmers often only or mostly care about that related problem, so it isn't the end of the line just when we hit this stumbling block. As far as undecidability goes, one possibility is to accept a subset of desired programs. For example, restrict the language to not be turing complete, and there is no problem. Another resolution to the problem of undecidability is to accept a _superset_ of the collection you want. This permits some programs without the property we want, but it's often acceptable anyway. A third approach is to attach proofs, and only accept a program with an attached and correct proof of said property. This is a huge concept, vital to understanding complexity theory. It may be undecidable to find a proof, but once it is found, it is decidable to check the proof against the program. Haskell takes something akin to the second approach, and allows errors to exist which would require too much work to eliminate at compile time. (Although the type system is a literal case of the first resolution). Python, by contrast, often values flexibility over correctness, regardless of how easy it might be to check an error at compile time. The two languages have different philosophies, and that is something to respect. The reduction to Rice's theorem does not respect the trade-off that Haskell is making, it ignores it. It may be a pipe dream to get everything ever, but that's not to say that the entire approach is invalid and that we should ignore how Haskell informs the PL discourse. For some reason both the Python and Haskell communities feel the other is foolish and ignorant, dismissing their opinions as unimportant babbling. I wish that would stop. -- Devin -- http://mail.python.org/mailman/listinfo/python-list
Re: Errin when executing a cgi script that sets a cookie in the browser
On 06/06/2013 04:53 AM, Νικόλαος Κούρας wrote: I have re-enabled 'suexec' and set cgi as default phphandler and then trying: print( cookie ) print( '''Content-type: text/html; charset=utf-8\n''' ) print( message ) - ni...@superhost.gr [~/www/data/apps]# [Thu Jun 06 13:51:28 2013] [error] [client 79.103.41.173] suexec failure: could not open log file [Thu Jun 06 13:51:28 2013] [error] [client 79.103.41.173] fopen: Permission denied [Thu Jun 06 13:51:28 2013] [error] [client 79.103.41.173] Premature end of script headers: koukos.py Even if dissable/enable suexec still this output error. This is only a guess but... The permissions on koukos.py have to be exactly right. Obviously if they are too restrictive Apache won't be able to read or execute it. But they can't be to open either -- in particular the file must have execute permission and must not have write permission for either group or others (write for user only). If the permissions are too open, Apache will try to write an error message to suexec.log. I suspect that your permissions (or file owner) is wrong on your suexec.log file (or containing directory) and that is the cause of the could not open log file message. So I think you have too problems: wrong permissions on koukos.py and wrong owner or permissions on suexec.log. For reference this is working here: -rw-r--r-- 1 apache apache 314 Jun 6 12:19 /var/log/httpd/suexec.log -rwxr-xr-x 1 me me 1113 Jun 5 14:40 koukos.py You'll need to adjust things for your particular Apache environment. As I said, this is only a guess. Hope it helps. -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
Τη Πέμπτη, 6 Ιουνίου 2013 3:44:52 μ.μ. UTC+3, ο χρήστης Steven D'Aprano έγραψε: py s = '999-Eυχή-του-Ιησού' py bytes_as_utf8 = s.encode('utf-8') py t = bytes_as_utf8.decode('iso-8859-7', errors='replace') py print(t) 999-EΟΟΞ�-ΟΞΏΟ-ΞΞ·ΟΞΏΟ errors='replace' mean dont break in case or error? You took the unicode 's' string you utf-8 bytestringed it. Then how its possible to ask for the utf8-bytestring to decode back to unicode string with the use of a different charset that the one used for encoding and thsi actually printed the filename in greek-iso? So that demonstrates part of your problem: even though your Linux system is using UTF-8, your terminal is probably set to ISO-8859-7. The interaction between these will lead to strange and disturbing Unicode errors. Yes i feel this is the problem too. Its a wonder to me why putty used by default greek-iso instead of utf-8 !! Please explain this t me because now that i begin to understand this encode/decode things i begin to like them! a) WHAT does it mean when a linux system is set to use utf-8? b) WHAT does it mean when a terminal client is set to use utf-8? c) WHAT happens when the two of them try to work together? So I believe I understand how your file name has become garbage. To fix it, make sure that your terminal is set to use UTF-8, and then rename it. Do the same with every file in the directory until the problem goes away. ni...@superhost.gr [~/www/cgi-bin]# echo $LS_OPTIONS --color=tty -F -a -b -T 0 Is this okey? The '-b' option is for to display a filename in binary mode? Indeed i have changed putty to use 'utf-8' and 'ls -l' now displays the file in correct greek letters. Switching putty's encoding back to 'greek-iso' then the *displayed* filanames shows in mojabike. WHAT is being displayed and what is actually stored as bytes is two different thigns right? Ευχη του Ιησου.mp3 EΟΟΞ�-ΟΞΏΟ-ΞΞ·ΟΞΏΟ is the way the filaname is displayed in the terminal depending on the encoding the terminal uses, correct? But no matter *how* its being dislayed those two are the same file? -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
Νικόλαος Κούρας nikos.gr...@gmail.com writes: ... # Load'em for fullpath in path: try: ... The error is: [Thu Jun 06 21:10:23 2013] [error] [client 79.103.41.173] File files.py, line 64 [Thu Jun 06 21:10:23 2013] [error] [client 79.103.41.173] for fullpath in path [Thu Jun 06 21:10:23 2013] [error] [client 79.103.41.173] ^ [Thu Jun 06 21:10:23 2013] [error] [client 79.103.41.173] SyntaxError: invalid syntax Doesn't os.listdir( ...) returns a list with all filenames? You should *read* and *understand* the error message! This is the same kind of confusion you had when I pointed you at the missing closing bracket some day ago, when you missed the meaning of the error and assume it's source is related to something completely different... In the specific case, your line 64 is missing an ending colon (:). ciao, lele. -- nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia. l...@metapensiero.it | -- Fortunato Depero, 1929. -- http://mail.python.org/mailman/listinfo/python-list
Re: Errin when executing a cgi script that sets a cookie in the browser
Τη Πέμπτη, 6 Ιουνίου 2013 9:40:04 μ.μ. UTC+3, ο χρήστης ru...@yahoo.com έγραψε: On 06/06/2013 04:53 AM, Νικόλαος Κούρας wrote: I have re-enabled 'suexec' and set cgi as default phphandler and then trying: print( cookie ) print( '''Content-type: text/html; charset=utf-8\n''' ) print( message ) - ni...@superhost.gr [~/www/data/apps]# [Thu Jun 06 13:51:28 2013] [error] [client 79.103.41.173] suexec failure: could not open log file [Thu Jun 06 13:51:28 2013] [error] [client 79.103.41.173] fopen: Permission denied [Thu Jun 06 13:51:28 2013] [error] [client 79.103.41.173] Premature end of script headers: koukos.py Even if dissable/enable suexec still this output error. This is only a guess but... The permissions on koukos.py have to be exactly right. Obviously if they are too restrictive Apache won't be able to read or execute it. But they can't be to open either -- in particular the file must have execute permission and must not have write permission for either group or others (write for user only). If the permissions are too open, Apache will try to write an error message to suexec.log. I suspect that your permissions (or file owner) is wrong on your suexec.log file (or containing directory) and that is the cause of the could not open log file message. So I think you have too problems: wrong permissions on koukos.py and wrong owner or permissions on suexec.log. For reference this is working here: -rw-r--r-- 1 apache apache 314 Jun 6 12:19 /var/log/httpd/suexec.log -rwxr-xr-x 1 me me 1113 Jun 5 14:40 koukos.py You'll need to adjust things for your particular Apache environment. As I said, this is only a guess. Hope it helps. Hello! thanks for trying to help. Here they are: ni...@superhost.gr [~/www/cgi-bin]# ls -l koukos.py -rwxr-xr-x 1 nikos nikos 1160 Jun 6 06:27 koukos.py* ni...@superhost.gr [~/www/cgi-bin]# ls -l /var/log/httpd/suexec.log -rw-rw-rw- 1 root apache 0 Jun 1 02:52 /var/log/httpd/suexec.log ni...@superhost.gr [~/www/cgi-bin]# ls -l /usr/local/apache/logs/suexec_log -rw-rw-r-- 1 root apache 675097 Jun 6 21:43 /usr/local/apache/logs/suexec_log I have applied to them the group 'apache' so Apache User can utilize them. But its still a wonder to me why two different suexec logs exist. Please tell me wht else you want me to try. -- http://mail.python.org/mailman/listinfo/python-list
[JOB] Look for a Full Time Plone Developer
Hi All, Please take a look at a new job opportunity for Python/Plone developers. Patrick Waldo, Project Manager Decernis http://decernis.com/ *Job Description: Full Time Python/Plone Developer* We are looking for a highly motivated and self-reliant developer to work on systems built with Plone in a small, but lively team. Our ideal candidate is not afraid to roll up their sleeves to tackle complex problems with their code as well as offer innovative solutions at the planning and design stages. The position also calls for both rapid prototyping for client meetings, maintaining current systems and fulfilling other tasks as necessary. This position requires experience in Plone administration, setting up backup and failover instances, optimizing the ZODB, testing and documentation. The job also entails creating clean user interfaces, building forms and integrating with Oracle. The position will begin with a six-month trial period at which point full-time employment will be re-evaluated based on performance. The candidate will be able to choose hours and work remotely, but must meet deadlines and report progress effectively. *Key Skills* · At least 3 years of Plone and Python development · At least 3 years web development (HTML, CSS, jQuery, etc.) · Server administration (Apache) · Oracle integration (cx_Oracle, SQLAlchemy, etc.) · Task oriented and solid project management skills · Data mining and data visualization experience is a plus · Java or Perl experience is a plus · Proficient English · Effective communication *About Decernis* Decernis is a global information systems company that works with industry leaders and government agencies to meet complex regulatory compliance and risk management needs in the areas of food, consumer products and industrial goods. We hold ourselves to high standards to meet the technically challenging areas that our clients face to ensure comprehensive, current and global solutions. Decernis has offices in Rockville, MD and Frankfurt, Germany as well as teams located around the world. For more information, please visit our website: http://www.decernis.com. *Contact* Please send resume, portfolio and cover letter to Cynthia Gamboa, * cgam...@decernis.com*. Decernis is an equal opportunity employer. -- http://mail.python.org/mailman/listinfo/python-list
Re: Errin when executing a cgi script that sets a cookie in the browser
Since cPanel is in charge of apache i ahve even: chown nobody:nobody to both of the suexec logs. ni...@superhost.gr [~/www/cgi-bin]# ls -l /usr/local/apache/logs/suexec_log -rw-rw-r-- 1 nobody nobody 675389 Jun 6 22:05 /usr/local/apache/logs/suexec_log ni...@superhost.gr [~/www/cgi-bin]# ls -l /var/log/httpd/su* -rw-rw-rw- 1 nobody nobody 0 Jun 1 02:52 /var/log/httpd/suexec_log Still same error :( -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
Τη Πέμπτη, 6 Ιουνίου 2013 10:03:02 μ.μ. UTC+3, ο χρήστης Lele Gaifax έγραψε: Νικόλαος Κούρας nikos.gr...@gmail.com writes: ... # Load'em for fullpath in path: try: ... The error is: [Thu Jun 06 21:10:23 2013] [error] [client 79.103.41.173] File files.py, line 64 [Thu Jun 06 21:10:23 2013] [error] [client 79.103.41.173] for fullpath in path [Thu Jun 06 21:10:23 2013] [error] [client 79.103.41.173] ^ [Thu Jun 06 21:10:23 2013] [error] [client 79.103.41.173] SyntaxError: invalid syntax Doesn't os.listdir( ...) returns a list with all filenames? You should *read* and *understand* the error message! This is the same kind of confusion you had when I pointed you at the missing closing bracket some day ago, when you missed the meaning of the error and assume it's source is related to something completely different... In the specific case, your line 64 is missing an ending colon (:). ciao, lele. Oh my God, was that simple and i was smashing my head to see where did i made a synatx error. Missed the colon! Well the error shoudl ahve said Hey man, you missed a colon!, that would help a lot. Now the error afetr fixithg that transformed to: [Thu Jun 06 22:13:49 2013] [error] [client 79.103.41.173] filename = fullpath.replace( '/home/nikos/public_html/data/apps/', '' ) [Thu Jun 06 22:13:49 2013] [error] [client 79.103.41.173] TypeError: expected bytes, bytearray or buffer compatible object but htats becaus eof these lines: # Give the path as a bytestring so that we'll get the filenames as bytestrings path = os.listdir( b'/home/nikos/public_html/data/apps/' ) # iterate over all filenames in the apps directory for fullpath in path: # Grabbing just the filename from path filename = fullpath.replace( '/home/nikos/public_html/data/apps/', '' ) i can remove the bianry openign from os.listdir but then this will not work. MRAB has told me that i need to open those paths and filenames as bytestreams and not as unicode strings. -- http://mail.python.org/mailman/listinfo/python-list
Python Community Training Events
Here are some upcoming Python community training events organized by the Triangle Python Users Group: PyOhio PyCamp 2013 offered July 22-26, 2013 at Ohio State University in conjunction with the PyOhio 2013 regional Python conference: http://trizpug.org/boot-camp/pyohio13/ Python Network and Web Programming Workshop offered August 5-9, 2013 at the University of North Carolina: http://trizpug.org/boot-camp/pywebpw13/ Toronto PyCamp 2013 offered August 12-16, 2013 at the University of Toronto in conjunction with the PyCon Canada 2013 national Python conference: http://trizpug.org/boot-camp/torpy13/ Seattle PyCamp 2013 offered September 9-13, 2013 at the University of Washington's Paul G. Allen Center for Computer Science and Engineering: http://trizpug.org/boot-camp/seapy13/ -- Sincerely, Chris Calloway UNC-CH Department of Marine Sciences 3313 Venable Hall CB 3300 Chapel Hill, NC 27599-3300 (919) 599-3530 -- http://mail.python.org/mailman/listinfo/python-list
Re: Errin when executing a cgi script that sets a cookie in the browser
Νικόλαος Κούρας nikos.gr...@gmail.com writes: I have re-enabled 'suexec' and set cgi as default phphandler and then trying: print( cookie ) print( '''Content-type: text/html; charset=utf-8\n''' ) print( message ) Did you tried running that by a standalone Python interpreter? Did you notice something strange, something like that an empty line is missing between headers and body? ciao, lele. -- nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia. l...@metapensiero.it | -- Fortunato Depero, 1929. -- http://mail.python.org/mailman/listinfo/python-list
Re: Errin when executing a cgi script that sets a cookie in the browser
Τη Πέμπτη, 6 Ιουνίου 2013 10:26:08 μ.μ. UTC+3, ο χρήστης Lele Gaifax έγραψε: Did you tried running that by a standalone Python interpreter? Did you notice something strange, something like that an empty line is missing between headers and body? No, nothing at all. Two '/n/n' are not required. Months now the way i'm printing headers is by: print( '''Content-type: text/html; charset=utf-8\n''' ) and the scripts owrk correctly in browser and in python interpreter too. -- http://mail.python.org/mailman/listinfo/python-list
Re: Errin when executing a cgi script that sets a cookie in the browser
Did you tried running that by a standalone Python interpreter? Did you notice something strange, something like that an empty line is missing between headers and body? He will get an extra blank line, since he added a newline character at the end of his Content-Type string. Skip -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
On 06/06/2013 19:13, Νικόλαος Κούρας wrote: Τη Πέμπτη, 6 Ιουνίου 2013 3:50:52 μ.μ. UTC+3, ο χρήστης MRAB έγραψε: If you're happy for that change to happen, then go ahead. I have made some modifications to the code you provided me but i think something that doesnt accur to me needs fixing. for example i switched: # Give the path as a bytestring so that we'll get the filenames as bytestrings path = b"/home/nikos/public_html/data/apps/" # Walk through the files. for root, dirs, files in os.walk( path ): for filename in files: to: # Give the path as a bytestring so that we'll get the filenames as bytestrings path = os.listdir( b'/home/nikos/public_html/data/apps/' ) os.listdir returns a list of the names of the objects in the given directory. # iterate over all filenames in the apps directory Exactly, all the names. for fullpath in path # Grabbing just the filename from path The name is a bytestring. Note, name, NOT full path. The following line will fail because the name is a bytestring, and you can't mix bytestrings with Unicode strings: filename = fullpath.replace( '/home/nikos/public_html/data/apps/', '' ) ^ bytestring ^ Unicode string ^ Unicode string I dont know if it has the same effect: Here is the the whole snippet: = # Give the path as a bytestring so that we'll get the filenames as bytestrings path = os.listdir( b'/home/nikos/public_html/data/apps/' ) # iterate over all filenames in the apps directory for fullpath in path # Grabbing just the filename from path filename = fullpath.replace( '/home/nikos/public_html/data/apps/', '' ) try: # Is this name encoded in utf-8? filename.decode('utf-8') except UnicodeDecodeError: # Decoding from UTF-8 failed, which means that the name is not valid utf-8 # It appears that this filename is encoded in greek-iso, so decode from that and re-encode to utf-8 new_filename = filename.decode('iso-8859-7').encode('utf-8') # rename filename form greek bytestream- utf-8 bytestream old_path = os.path.join(root, filename) new_path = os.path.join(root, new_filename) os.rename( old_path, new_path ) # # Compute a set of current fullpaths path = os.listdir( '/home/nikos/public_html/data/apps/' ) # Load'em for fullpath in path: try: # Check the presence of a file against the database and insert if it doesn't exist cur.execute('''SELECT url FROM files WHERE url = "" (fullpath,) ) data = ""#URL is unique, so should only be one if not data: # First time for file; primary key is automatic, hit is defaulted cur.execute('''INSERT INTO files (url, host, lastvisit) VALUES (%s, %s, %s)''', (fullpath, host, lastvisit) ) except pymysql.ProgrammingError as e: print( repr(e) ) == The error is: [Thu Jun 06 21:10:23 2013] [error] [client 79.103.41.173] File "files.py", line 64 [Thu Jun 06 21:10:23 2013] [error] [client 79.103.41.173] for fullpath in path [Thu Jun 06 21:10:23 2013] [error] [client 79.103.41.173]^ [Thu Jun 06 21:10:23 2013] [error] [client 79.103.41.173] SyntaxError: invalid syntax Doesn't os.listdir( ...) returns a list with all filenames? But then again when replacing take place to shert the fullpath to just the filane i think it doesn't not work because the os.listdir was opened as bytestring and not as a string What am i doing wrong? You're changing things without checking what they do! -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
Τη Πέμπτη, 6 Ιουνίου 2013 10:42:25 μ.μ. UTC+3, ο χρήστης MRAB έγραψε: On 06/06/2013 19:13, οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½ οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½ wrote: οΏ½οΏ½ οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½, 6 οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½ 2013 3:50:52 οΏ½.οΏ½. UTC+3, οΏ½ οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½ MRAB οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½: If you're happy for that change to happen, then go ahead. I have made some modifications to the code you provided me but i think something that doesnt accur to me needs fixing. for example i switched: # Give the path as a bytestring so that we'll get the filenames as bytestrings path = b/home/nikos/public_html/data/apps/ # Walk through the files. for root, dirs, files in os.walk( path ): for filename in files: to: # Give the path as a bytestring so that we'll get the filenames as bytestrings path = os.listdir( b'/home/nikos/public_html/data/apps/' ) os.listdir returns a list of the names of the objects in the given directory. # iterate over all filenames in the apps directory Exactly, all the names. for fullpath in path # Grabbing just the filename from path The name is a bytestring. Note, name, NOT full path. The following line will fail because the name is a bytestring, and you can't mix bytestrings with Unicode strings: filename = fullpath.replace( '/home/nikos/public_html/data/apps/', '' ) οΏ½ οΏ½ οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½ ^ bytestringοΏ½οΏ½οΏ½ οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½ ^ Unicode stringοΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½ οΏ½ οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½ ^ Unicode string I dont know if it has the same effect: Here is the the whole snippet: = # Give the path as a bytestring so that we'll get the filenames as bytestrings path = os.listdir( b'/home/nikos/public_html/data/apps/' ) # iterate over all filenames in the apps directory for fullpath in path # Grabbing just the filename from path filename = fullpath.replace( '/home/nikos/public_html/data/apps/', '' ) try: # Is this name encoded in utf-8? filename.decode('utf-8') except UnicodeDecodeError: # Decoding from UTF-8 failed, which means that the name is not valid utf-8 # It appears that this filename is encoded in greek-iso, so decode from that and re-encode to utf-8 new_filename = filename.decode('iso-8859-7').encode('utf-8') # rename filename form greek bytestream- utf-8 bytestream old_path = os.path.join(root, filename) new_path = os.path.join(root, new_filename) os.rename( old_path, new_path ) # # Compute a set of current fullpaths path = os.listdir( '/home/nikos/public_html/data/apps/' ) # Load'em for fullpath in path: try: # Check the presence of a file against the database and insert if it doesn't exist cur.execute('''SELECT url FROM files WHERE url = %s''', (fullpath,) ) data = cur.fetchone()#URL is unique, so should only be one if not data: # First time for file; primary key is automatic, hit is defaulted cur.execute('''INSERT INTO files (url, host, lastvisit) VALUES (%s, %s, %s)''', (fullpath, host, lastvisit) ) except pymysql.ProgrammingError as e: print( repr(e) ) == The error is: [Thu Jun 06 21:10:23 2013] [error] [client 79.103.41.173] File files.py, line 64 [Thu Jun 06 21:10:23 2013] [error] [client 79.103.41.173] for fullpath in path [Thu Jun 06 21:10:23 2013] [error] [client 79.103.41.173] ^ [Thu Jun 06 21:10:23 2013] [error] [client 79.103.41.173] SyntaxError: invalid syntax Doesn't os.listdir( ...) returns a list with all filenames? But then again when replacing take place to shert the fullpath to just the filane i think it doesn't not work because the os.listdir was opened as bytestring and not as a string What am i doing wrong? You're changing things without checking what they do! Ah yes, it retruens filenames, not path/to/filenames # # Give the path as a bytestring so that we'll get the filenames as bytestrings path = os.listdir( b'/home/nikos/public_html/data/apps/' ) # iterate over all filenames in the apps directory for filename
Re: Errin when executing a cgi script that sets a cookie in the browser
Something else i need to try so for 'suexec' to be able to open its own lof file? What a weird error that is. An Apache's extension that can open its own log file. -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
Actually about the Spurious procedure iam happy with myelf that came up with this: # Delete spurious cur.execute('''SELECT url FROM files''') data = cur.fetchall() for filename in path url = '/home/nikos/public_html/data/apps/' + filename urls.add( url ) for url in data: if url not in urls cur.execute('''DELETE FROM files WHERE url = %s''', (url,) ) Ddint try it yet though, need to anwer previous post's a) Is it correct that the first time i open os.listdir() as binary to grab the fileenames as bytestring and the 2nd normally to grab the filanems as unicode strings? -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
Νικόλαος Κούρας nikos.gr...@gmail.com writes: Now the error afetr fixithg that transformed to: [Thu Jun 06 22:13:49 2013] [error] [client 79.103.41.173] filename = fullpath.replace( '/home/nikos/public_html/data/apps/', '' ) [Thu Jun 06 22:13:49 2013] [error] [client 79.103.41.173] TypeError: expected bytes, bytearray or buffer compatible object MRAB has told me that i need to open those paths and filenames as bytestreams and not as unicode strings. Yes, that way the function will return a list of bytes instances. Knowing that, consider the following example, that should ring a bell: $ python3 Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 09:59:04) [GCC 4.7.2] on linux Type help, copyright, credits or license for more information. path = bsome/path path.replace('some', '') Traceback (most recent call last): File stdin, line 1, in module TypeError: expected bytes, bytearray or buffer compatible object path.replace(b'some', b'') b'/path' ciao, lele. -- nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia. l...@metapensiero.it | -- Fortunato Depero, 1929. -- http://mail.python.org/mailman/listinfo/python-list
Re: Errin when executing a cgi script that sets a cookie in the browser
Skip Montanaro s...@pobox.com writes: He will get an extra blank line, since he added a newline character at the end of his Content-Type string. Right, missed that, sorry for the noise. ciao, lele. -- nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia. l...@metapensiero.it | -- Fortunato Depero, 1929. -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
Τη Πέμπτη, 6 Ιουνίου 2013 11:25:15 μ.μ. UTC+3, ο χρήστης Lele Gaifax έγραψε: Νικόλαος Κούρας nikos.gr...@gmail.com writes: Now the error afetr fixithg that transformed to: [Thu Jun 06 22:13:49 2013] [error] [client 79.103.41.173] filename = fullpath.replace( '/home/nikos/public_html/data/apps/', '' ) [Thu Jun 06 22:13:49 2013] [error] [client 79.103.41.173] TypeError: expected bytes, bytearray or buffer compatible object MRAB has told me that i need to open those paths and filenames as bytestreams and not as unicode strings. Yes, that way the function will return a list of bytes instances. Knowing that, consider the following example, that should ring a bell: $ python3 Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 09:59:04) [GCC 4.7.2] on linux Type help, copyright, credits or license for more information. path = bsome/path path.replace('some', '') Traceback (most recent call last): File stdin, line 1, in module TypeError: expected bytes, bytearray or buffer compatible object path.replace(b'some', b'') b'/path' Ah yes, very logical, i should have though of that. Tahnks here is what i have up until now with many corrections. # # Get filenames of the apps directory as bytestrings path = os.listdir( b'/home/nikos/public_html/data/apps/' ) # iterate over all filenames in the apps directory for filename in path: # Grabbing just the filename from path try: # Is this name encoded in utf-8? filename.decode('utf-8') except UnicodeDecodeError: # Decoding from UTF-8 failed, which means that the name is not valid utf-8 # It appears that this filename is encoded in greek-iso, so decode from that and re-encode to utf-8 new_filename = filename.decode('iso-8859-7').encode('utf-8') # rename filename form greek bytestreams -- utf-8 bytestreams old_path = b'/home/nikos/public_html/data/apps/' + b'filename') new_path = b'/home/nikos/public_html/data/apps/' + b'new_filename') os.rename( old_path, new_path ) # # Get filenames of the apps directory as unicode path = os.listdir( '/home/nikos/public_html/data/apps/' ) # Load'em for filename in path: try: # Check the presence of a file against the database and insert if it doesn't exist cur.execute('''SELECT url FROM files WHERE url = %s''', (filename,) ) data = cur.fetchone()#URL is unique, so should only be one if not data: # First time for file; primary key is automatic, hit is defaulted cur.execute('''INSERT INTO files (url, host, lastvisit) VALUES (%s, %s, %s)''', (filename, host, lastvisit) ) except pymysql.ProgrammingError as e: print( repr(e) ) # # Empty set that will be filled in with 'path/to/filename' of path dir urls = () # Build a set of 'path/to/filename' based on the objects of path dir for filename in path url = '/home/nikos/public_html/data/apps/' + filename urls.add( url ) # Delete spurious cur.execute('''SELECT url FROM files''') data = cur.fetchall() # Check database's urls against path's urls for url in data: if url not in urls cur.execute('''DELETE FROM files WHERE url = %s''', (url,) ) == I think its ready! But i want to hear from you, before i try it! :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
Has some errors: # # Get filenames of the apps directory as bytestrings path = os.listdir( b'/home/nikos/public_html/data/apps/' ) # iterate over all filenames in the apps directory for filename in path: # Grabbing just the filename from path try: # Is this name encoded in utf-8? filename.decode('utf-8') except UnicodeDecodeError: # Decoding from UTF-8 failed, which means that the name is not valid utf-8 # It appears that this filename is encoded in greek-iso, so decode from that and re-encode to utf-8 new_filename = filename.decode('iso-8859-7').encode('utf-8') # rename filename form greek bytestreams -- utf-8 bytestreams old_path = b'/home/nikos/public_html/data/apps/' + b'filename') new_path = b'/home/nikos/public_html/data/apps/' + b'new_filename') os.rename( old_path, new_path ) # # Get filenames of the apps directory as unicode path = os.listdir( '/home/nikos/public_html/data/apps/' ) # Load'em for filename in path: try: # Check the presence of a file against the database and insert if it doesn't exist cur.execute('''SELECT url FROM files WHERE url = %s''', (filename,) ) data = cur.fetchone()#filename is unique, so should only be one if not data: # First time for file; primary key is automatic, hit is defaulted cur.execute('''INSERT INTO files (url, host, lastvisit) VALUES (%s, %s, %s)''', (filename, host, lastvisit) ) except pymysql.ProgrammingError as e: print( repr(e) ) # path = os.listdir( '/home/nikos/public_html/data/apps/' ) filenames = () # Build a set of 'path/to/filename' based on the objects of path dir for filename in path filenames.add( filename ) # Delete spurious cur.execute('''SELECT url FROM files''') data = cur.fetchall() # Check database's filenames against path's filenames for filename in data: if filename not in filenames cur.execute('''DELETE FROM files WHERE url = %s''', (filename,) ) --- The only problem now is the bytestrings: ni...@superhost.gr [~/www/cgi-bin]# [Thu Jun 06 23:50:42 2013] [error] [client 79.103.41.173] File files.py, line 78 [Thu Jun 06 23:50:42 2013] [error] [client 79.103.41.173] old_path = b'/home/nikos/public_html/data/apps/' + b'filename') [Thu Jun 06 23:50:42 2013] [error] [client 79.103.41.173] ^ [Thu Jun 06 23:50:42 2013] [error] [client 79.103.41.173] SyntaxError: invalid syntax Dont know how to add a bytestremed path to a bytestream filename -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
I'm very sorry for continuous pastes. Didnt include the whole thing before. Here it is: # # Get filenames of the path dir as bytestrings path = os.listdir( b'/home/nikos/public_html/data/apps/' ) # iterate over all filenames in the apps directory for filename in path: # Grabbing just the filename from path try: # Is this name encoded in utf-8? filename.decode('utf-8') except UnicodeDecodeError: # Decoding from UTF-8 failed, which means that the name is not valid utf-8 # It appears that this filename is encoded in greek-iso, so decode from that and re-encode to utf-8 new_filename = filename.decode('iso-8859-7').encode('utf-8') # rename filename form greek bytestreams -- utf-8 bytestreams old_path = b'/home/nikos/public_html/data/apps/' + b'filename') new_path = b'/home/nikos/public_html/data/apps/' + b'new_filename') os.rename( old_path, new_path ) # # Get filenames of the apps directory as unicode path = os.listdir( '/home/nikos/public_html/data/apps/' ) # Load'em for filename in path: try: # Check the presence of a file against the database and insert if it doesn't exist cur.execute('''SELECT url FROM files WHERE url = %s''', (filename,) ) data = cur.fetchone()#filename is unique, so should only be one if not data: # First time for file; primary key is automatic, hit is defaulted cur.execute('''INSERT INTO files (url, host, lastvisit) VALUES (%s, %s, %s)''', (filename, host, lastvisit) ) except pymysql.ProgrammingError as e: print( repr(e) ) # path = os.listdir( '/home/nikos/public_html/data/apps/' ) filenames = () # Build a set of 'path/to/filename' based on the objects of path dir for filename in path filenames.add( filename ) # Delete spurious cur.execute('''SELECT url FROM files''') data = cur.fetchall() # Check database's filenames against path's filenames for filename in data: if filename not in filenames cur.execute('''DELETE FROM files WHERE url = %s''', (filename,) ) = Just the bytestream error and then i belive its ready this time. -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
Νικόλαος Κούρας nikos.gr...@gmail.com writes: Tahnks here is what i have up until now with many corrections. I'm afraid many more are needed :-) ... # rename filename form greek bytestreams -- utf-8 bytestreams old_path = b'/home/nikos/public_html/data/apps/' + b'filename') new_path = b'/home/nikos/public_html/data/apps/' + b'new_filename') os.rename( old_path, new_path ) a) there are two syntax errors, you have spurious close brackets there b) you are basically assigning *constant* expressions to both variables, most probably not what you meant ciao, lele. -- nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia. l...@metapensiero.it | -- Fortunato Depero, 1929. -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
Νικόλαος Κούρας nikos.gr...@gmail.com writes: The only problem now is the bytestrings: *One*, not the *only*. ni...@superhost.gr [~/www/cgi-bin]# [Thu Jun 06 23:50:42 2013] [error] [client 79.103.41.173] File files.py, line 78 [Thu Jun 06 23:50:42 2013] [error] [client 79.103.41.173] old_path = b'/home/nikos/public_html/data/apps/' + b'filename') [Thu Jun 06 23:50:42 2013] [error] [client 79.103.41.173] ^ [Thu Jun 06 23:50:42 2013] [error] [client 79.103.41.173] SyntaxError: invalid syntax Dont know how to add a bytestremed path to a bytestream filename Come on Niklos, either you learn from what I (and others) try to teach you, or I'm afraid you won't get more hints... this list cannot become your remote editor tool! *Read* the error message, *look* at the arrow (i.e. the caret character ^), *understand* what that is trying to tell you... ciao, lele. -- nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia. l...@metapensiero.it | -- Fortunato Depero, 1929. -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
On 06/06/2013 22:07, Lele Gaifax wrote: Νικόλαος Κούρας nikos.gr...@gmail.com writes: Tahnks here is what i have up until now with many corrections. I'm afraid many more are needed :-) ... # rename filename form greek bytestreams -- utf-8 bytestreams old_path = b'/home/nikos/public_html/data/apps/' + b'filename') new_path = b'/home/nikos/public_html/data/apps/' + b'new_filename') os.rename( old_path, new_path ) a) there are two syntax errors, you have spurious close brackets there b) you are basically assigning *constant* expressions to both variables, most probably not what you meant Yet again, he's changed things unnecessarily, and the code was meant only as a one-time fix to correct the encoding of some filenames. :-( -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
On 06Jun2013 05:04, =?utf-8?B?zp3Or866zr/PgiDOk866z4EzM866?= nikos.gr...@gmail.com wrote: | We are in test mode so i dont know if when renaming actually take place what the encodings will be. | Shall i switch off test mode and try it for real? I would make a copy. Since you're renaming stuff, hard links would do: cp -rpl original-dir test-dir Then test stuff in test-dir. -- Cameron Simpson c...@zip.com.au Too much of a good thing is never enough. - Luba -- http://mail.python.org/mailman/listinfo/python-list
trigger at TDM/2 only
Hi, I have a process that I can trigger only at a certain time. Assume I have a TDM period of 10min, that means, I can only fire my trigger at the 5th minute of every 10min cycle i.e. at XX:05, XX:15, XX:25... For hat I came up with following algorithm which oly leaves the waiting while loop if minute % TDM/2 is 0 but not if minute % TDM is 0: min = datetime.datetime.now().timetuple().tm_hour*60 + datetime.datetime.now().timetuple().tm_min while not (min%tdm_timeslot != 0 ^ min%(int(tdm_timeslot/2)) != 0): time.sleep(10) logger.debug(WAIT +str(datetime.datetime.now().timetuple().tm_hour*60 + datetime.datetime.now().timetuple().tm_min)) logger.debug(str(min%(int(tdm_timeslot/2)))+ - +str(min%tdm_timeslot)) min = datetime.datetime.now().timetuple().tm_hour*60 + datetime.datetime.now().timetuple().tm_min logger.debug(RUN UPDATE CHECK...) But weird enough, the output I get is something like this: I would expect my while to exit the loop as soon as the minute turns 1435... why is it staying in? What am I doing wrong here? WAIT 1434 3 - 3 WAIT 1434 4 - 4 WAIT 1434 4 - 4 WAIT 1434 4 - 4 WAIT 1434 4 - 4 WAIT 1434 4 - 4 WAIT 1435 4 - 4 WAIT 1435 0 - 5 WAIT 1435 0 - 5 WAIT 1435 0 - 5 WAIT 1435 0 - 5 WAIT 1435 0 - 5 WAIT 1436 0 - 5 RUN UPDATE CHECK... Thank you for any assistance! Ron -- http://mail.python.org/mailman/listinfo/python-list
Re: trigger at TDM/2 only
On 06/06/2013 08:03 PM, cerr wrote: Hi, I have a process that I can trigger only at a certain time. Assume I have a TDM period of 10min, that means, I can only fire my trigger at the 5th minute of every 10min cycle i.e. at XX:05, XX:15, XX:25... For hat I came up with following algorithm which oly leaves the waiting while loop if minute % TDM/2 is 0 but not if minute % TDM is 0: min = datetime.datetime.now().timetuple().tm_hour*60 + datetime.datetime.now().timetuple().tm_min while not (min%tdm_timeslot != 0 ^ min%(int(tdm_timeslot/2)) != 0): You might have spent three minutes and simplified this for us. And in the process discovered the problem. (BTW, min() is a builtin function, so it's not really a good idea to be shadowing it.) You didn't give python version, so my sample is assuming Python 2.7 For your code it shouldn't matter. tdm = 10 tdm2 = 5 y = min(3,4) print y for now in range(10,32): print now, now%tdm, now%tdm2, print not(now % tdm !=0 ^ now%tdm2 !=0) #bad print not((now % tdm !=0) ^ (now%tdm2 !=0)) #good Your problem is one of operator precedence. Notice that ^ has a higher precedence than != operator, so you need the parentheses I added in the following line. What I don't understand is why you used this convoluted approach. Why not print now%tdm != tdm2 For precedence rules, see: http://docs.python.org/2/reference/expressions.html#operator-precedence -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: trigger at TDM/2 only
On 07/06/2013 01:03, cerr wrote: Hi, I have a process that I can trigger only at a certain time. Assume I have a TDM period of 10min, that means, I can only fire my trigger at the 5th minute of every 10min cycle i.e. at XX:05, XX:15, XX:25... For hat I came up with following algorithm which oly leaves the waiting while loop if minute % TDM/2 is 0 but not if minute % TDM is 0: min = datetime.datetime.now().timetuple().tm_hour*60 + datetime.datetime.now().timetuple().tm_min while not (min%tdm_timeslot != 0 ^ min%(int(tdm_timeslot/2)) != 0): time.sleep(10) logger.debug(WAIT +str(datetime.datetime.now().timetuple().tm_hour*60 + datetime.datetime.now().timetuple().tm_min)) logger.debug(str(min%(int(tdm_timeslot/2)))+ - +str(min%tdm_timeslot)) min = datetime.datetime.now().timetuple().tm_hour*60 + datetime.datetime.now().timetuple().tm_min logger.debug(RUN UPDATE CHECK...) But weird enough, the output I get is something like this: I would expect my while to exit the loop as soon as the minute turns 1435... why is it staying in? What am I doing wrong here? WAIT 1434 3 - 3 WAIT 1434 4 - 4 WAIT 1434 4 - 4 WAIT 1434 4 - 4 WAIT 1434 4 - 4 WAIT 1434 4 - 4 WAIT 1435 4 - 4 WAIT 1435 0 - 5 WAIT 1435 0 - 5 WAIT 1435 0 - 5 WAIT 1435 0 - 5 WAIT 1435 0 - 5 WAIT 1436 0 - 5 RUN UPDATE CHECK... Possibly it's due to operator precedence. The bitwise operators , | and ^ have a higher precedence than comparisons such as !=. A better condition might be: min % tdm_timeslot != tdm_timeslot // 2 or, better yet, work out how long before the next trigger time and then sleep until then. -- http://mail.python.org/mailman/listinfo/python-list
Re: Bools and explicitness [was Re: PyWart: The problem with print]
On Jun 7, 3:59 am, Mark Janssen dreamingforw...@gmail.com wrote: Okay, I'm going straighten out you foo(l)s once and for all. Gosh, really?! THANKS. Python has seduced us all into lazy typing. That's what it is. Bulshytt. If you have no idea what polymorphism is, you shouldn't even be participating in this conversation. The fact is, that none of us is close enough to God More bulshytt. -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
On 06Jun2013 11:46, =?utf-8?B?zp3Or866zr/PgiDOk866z4EzM866?= nikos.gr...@gmail.com wrote: | Τη Πέμπτη, 6 Ιουνίου 2013 3:44:52 μ.μ. UTC+3, ο χρήστης Steven D'Aprano έγραψε: | py s = '999-Eυχή-του-Ιησού' | py bytes_as_utf8 = s.encode('utf-8') | py t = bytes_as_utf8.decode('iso-8859-7', errors='replace') | py print(t) | 999-EΟΟΞ�-ΟΞΏΟ-ΞΞ·ΟΞΏΟ | | errors='replace' mean dont break in case or error? Yes. The result will be correct for correct iso-8859-7 and slightly mangled for something that would not decode smoothly. | You took the unicode 's' string you utf-8 bytestringed it. | Then how its possible to ask for the utf8-bytestring to decode | back to unicode string with the use of a different charset that the | one used for encoding and thsi actually printed the filename in | greek-iso? It is easily possible, as shown above. Does it make sense? Normally not, but Steven is demonstrating how your mv exercises have behaved: a rename using utf-8, then a _display_ using iso-8859-7. | So that demonstrates part of your problem: even though your Linux system | is using UTF-8, your terminal is probably set to ISO-8859-7. The | interaction between these will lead to strange and disturbing Unicode | errors. | | Yes i feel this is the problem too. | Its a wonder to me why putty used by default greek-iso instead of utf-8 !! Putty will get its terminal setting from the system you came from. I suppose Windows of some kind. If you look at Putty's settings you may be able to specify UTF-8 explicitly; not sure. If you can, do that. At least there will be one less layer of confusion to debug. | Please explain this t me because now that i begin to understand | this encode/decode things i begin to like them! | | a) WHAT does it mean when a linux system is set to use utf-8? It means the locale settings _for the current process_ are set for UTF-8. The locale command will show you the current state. There will also be some system settings with defaults for stuff started up by the system. On CentOS and RedHat that is probably the file: /etc/sysconfig/i18n _However_, when you ssh in to the system using Putty or another ssh client, the settings at your local end are passes to the remote ssh session. In this way different people using different locales can ssh in and get the locales they expect to use. Of course, of the locale settings differ and these people are working on the same files and text, madness will ensue. | b) WHAT does it mean when a terminal client is set to use utf-8? It means the _display_ end of the terminal will render characters using UTF-8. Data comes from the remote system as a sequence of bytes. The terminal receives these bytes and _decodes_ them using utf-8 (or whatever) in order to decides what characters to display. | c) WHAT happens when the two of them try to work together? If everything matches, it is all good. If the locales do not match, the mismatch will result in an undesired bytes-characters encode/decode step somewhere, and something will display incorrectly or be entered as input incorrectly. | So I believe I understand how your file name has become garbage. To fix | it, make sure that your terminal is set to use UTF-8, and then rename it. | Do the same with every file in the directory until the problem goes away. | | ni...@superhost.gr [~/www/cgi-bin]# echo $LS_OPTIONS | --color=tty -F -a -b -T 0 | | Is this okey? The '-b' option is for to display a filename in binary mode? Probably. man ls will tell you. Personally, I unalias ls on RedHat systems (and any other system where an alias has been set up). I want ls to do what I say, not what someone else thought was a good idea. | Indeed i have changed putty to use 'utf-8' and 'ls -l' now displays | the file in correct greek letters. Switching putty's encoding back | to 'greek-iso' then the *displayed* filanames shows in mojabike. Exactly so. | WHAT is being displayed and what is actually stored as bytes is two different thigns right? Yes. Display requires the byte stream to be decoded. Wrong decoding display wrong characters/glyphs. | Ευχη του Ιησου.mp3 | EΟΟΞ�-ΟΞΏΟ-ΞΞ·ΟΞΏΟ | | is the way the filaname is displayed in the terminal depending | on the encoding the terminal uses, correct? But no matter *how* its | being dislayed those two are the same file? In principle, yes. Nothing has changed on the filesystem itself. Cheers, -- Cameron Simpson c...@zip.com.au in rec.moto, jsh wrote: Dan Nitschke wrote: Ged Martin wrote: On Sat, 17 May 1997 16:53:33 +, Dan Nitschke scribbled: (And you stay *out* of my dreams, you deviant little weirdo.) Yeah, yeah, that's what you're saying in _public_ Feh. You know nothing of my dreams. I dream entirely in text (New Century Schoolbook bold oblique 14 point), and never in color. I once dreamed I was walking down a flowchart of my own code, and a waterfall of semicolons was chasing me. (I hid behind a global variable until they went
Re: Bools and explicitness [was Re: PyWart: The problem with print]
On Jun 7, 2:39 am, Devin Jeanpierre jeanpierr...@gmail.com wrote: Languages do not exist in a vacuum. They do if all you use them for is academic point scoring over practical purposes. -- http://mail.python.org/mailman/listinfo/python-list
Re: Bools and explicitness [was Re: PyWart: The problem with print]
On Thu, Jun 6, 2013 at 9:49 AM, Rick Johnson rantingrickjohn...@gmail.comwrote: Congrats: Again you join the ranks of most children who make excuses for their foolish actions along the lines of: Hey, they did it first! Well, the lemmings get what they deserve i suppose. Lemmings don't really jump off cliffs. The Disney film documenting it was staged by a film crew who'd -heard- Lemmings did, and forced the little guys over a cliff in the name of saving time. http://en.wikipedia.org/wiki/Lemming -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
On Thu, 06 Jun 2013 12:17:16 -0700, Νικόλαος Κούρας wrote: i can remove the bianry openign from os.listdir but then this will not work. MRAB has told me that i need to open those paths and filenames as bytestreams and not as unicode strings. Do you understand why? If you do not understand *why* we tell you to do a thing, then you have no understanding and are doing Cargo Cult programming: http://en.wikipedia.org/wiki/Cargo_cult_programming http://en.wikipedia.org/wiki/Cargo_cult MRAB tells you to work with the bytes, because the file names' bytes are invalid when used as UTF-8. If you fix the file names by renaming using a terminal set to UTF-8, then they will be valid and you can forget about working with bytes. Working with bytes is only for when the file names are turned to garbage. Your file names (some of them) are turned to garbage. Fix them, and then use file names as strings. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
On Thu, 06 Jun 2013 13:56:36 -0700, Νικόλαος Κούρας wrote: SyntaxError: invalid syntax Dont know how to add a bytestremed path to a bytestream filename Nikos, READ THE ERROR MESSAGE!!! The error doesn't say anything about *adding*. It is a SyntaxError. Please stop flooding us with dozens and dozens of trivial posts asking the same questions over and over again. There are well over 120 posts in this thread, it is impossible for anyone to keep track of it. * Do not send a new post every time you make a small change to the code. * Do not send a new post every time you make a typo and get a SyntaxError. * READ THE ERROR MESSAGES and try to understand them first. * SyntaxError means YOU HAVE MADE A TYPING MISTAKE. * SyntaxError means that your code is not executed at all. Not a single line of code is run. If no code is running, the problem cannot possibly be with add or some other operation. If your car will not start, the problem cannot be with the brakes. If your program will not start, the problem cannot be with adding two byte strings. * You can fix syntax errors yourself. READ THE CODE that has the syntax error and LOOK FOR WHAT IS WRONG. Then fix it. * Don't tell us when you have fixed it. Nobody cares. Just fix it. Here is the line of code again: old_path = b'/home/nikos/public_html/data/apps/' + b'filename') There is a syntax error in this line of code. Hint: here are some simple examples of the same syntax error: a = b + c) x = y * z) alist.sort()) assert 1+1 == 2) Can you see the common factor? Each of those lines will give the same syntax error as your line. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Bools and explicitness [was Re: PyWart: The problem with print]
Python has seduced us all into lazy typing. That's what it is. Bulshytt. If you have no idea what polymorphism is, you shouldn't even be participating in this conversation. I am aware of what it means, but Python doesn't really have it (although it may evolve to it with annotations). But then these debates were over a decade ago. MarkJ Tacoma, Washington -- http://mail.python.org/mailman/listinfo/python-list