Re: Changing filenames from Greeklish = Greek (subprocess complain)
Τη Τρίτη, 4 Ιουνίου 2013 1:46:53 π.μ. UTC+3, ο χρήστης Steven D'Aprano έγραψε: Not so -- it actually shows correctly, provided you use the right encoding. Tell your browser to view the page as UTF-8, and the file name is displayed correctly. I can't believe Chrome whcih by default uses utf8 chosed iso-8859-1 to presnt the filenames. You were right Steven, when i explicitly told him to presnt page sin utf8 it then started to show tha filesname correctly. I now tentatively believe that the file names are correct, using the UTF-8 encoding. But you can help confirm this: * What operating system are you using? If Linux, what distro and version? * What is the output of the locale command? First of all thank you very much for being so cooperative, i appreciate it. Here is some of my system insight you wanted to see. ni...@superhost.gr [~]# uname -a Linux nikos.superhost.gr 2.6.32-042stab075.2 #1 SMP Tue May 14 20:38:14 MSK 2013 x86_64 x86_64 x86_64 GNU/Linux ni...@superhost.gr [~]# 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= ni...@superhost.gr [~]# I'am using CentOS v6.4 becaue it is the only linux OS that supports cPanel which my clients need to administer their websites. Hese is also how the terminal presents my filenames. ni...@superhost.gr [~]# ls -l www/data/apps/ total 368548 drwxr-xr-x 2 nikos nikos 4096 Jun 3 12:07 ./ 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 -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 -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\ 2013.exe -rw-r--r-- 1 nikos nikos 236032 Jun 2 19:31 Skepsou\ enan\ arithmo!.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 -rw-r--r-- 1 nikos nikos 3511233 Jun 3 12:07 ΞΟ ΟΞ�\ Ο ΞΏΟ.mp3 ni...@superhost.gr [~]# Its wird, because as locale showed from above terminal is set to 'utf-8' but the greek filename cannot be viewed properly. I must say though, that i have renamed it from my Windows 8 system and then uploaded via FileZilla to my remote webhost server. Maybe windows 8 is causing this? I'll try renaming it via terminal too. f you want to see soemhtign else please ask me to show you Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Too many python installations. Should i remove them all and install the latest?
Could you please install them because i need to work? a) pip (so that i can successfully run 'pip install pymysql' b) development tools I wiped the while perl away (leaving intact 2.6) but i wiped out pip at the proces to. -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
Τη Τρίτη, 4 Ιουνίου 2013 1:37:37 π.μ. UTC+3, ο χρήστης Steven D'Aprano έγραψε: It looks like your client is ignoring the charset header, and interpreting the bytes as Latin-1 when they are actually ISO-8859-7. py s = 'Eυχή του Ιησού.mp3' py print(s.encode('ISO-8859-7').decode('latin-1')) Eõ÷Þ ôïõ Éçóïý.mp3 which matches what you see. If you can manually tell your client to use ISO-8859-7, you should see it correctly. I think is this is the case too steven, but it suprises me that Chrome ignores the charset header. Actually when i toild explicitly Chrome to display everythign as utf-8 it presented the filanem properly. py print(s.encode('ISO-8859-7').decode('latin-1')) Why you are encoding the 's' string to greek-iso? Isn't it by itself in greek-iso since it uses greek letters? -- http://mail.python.org/mailman/listinfo/python-list
RE: Beginner question
That doesn't even works because input() is the same as eval(raw_input()). So you'll get a NameError exception. I think you know that. Perhaps you mean raw_input() instead of input(). In that case the answer is yes, it can be more 'efficient' because the if-then-else clause always breaks the while loop. I think you are looking for is a switch statement, which Python don't have. You can use the following structure to emulate a switch statement: def function1(): if raw_input() in option1: print('he tumbles over you') else: print('he stabs you') def function2(): if raw_input() in option2: print('you trip him up') else: print('he stabs you') def default(): print 'DEFAULT' switch = { option1: function1, option2: function2 } switch.get(randomizer, default)() Note that switch is a dictionary and you can use it without creating a variable, for example: { option1: function1, option2: function2 }.get(randomizer, default)() Date: Mon, 3 Jun 2013 20:39:28 -0700 Subject: Beginner question From: eschneide...@comcast.net To: python-list@python.org Is there a more efficient way of doing this? Any help is gratly appreciated. import random def partdeux(): print('''A man lunges at you with a knife! Do you DUCK or PARRY?''') option1=('duck') option2=('parry') optionsindex=[option1, option2] randomizer=random.choice(optionsindex) while randomizer==option1: if input() in option1: print('he tumbles over you') break else: print('he stabs you') break while randomizer==option2: if input() in option2: print('you trip him up') break else: print('he stabs you') break partdeux() -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Too many python installations. Should i remove them all and install the latest?
On 4 Jun 2013 07:44, Νικόλαος Κούρας nikos.gr...@gmail.com wrote: Could you please install them because i need to work? a) pip (so that i can successfully run 'pip install pymysql' b) development tools I wiped the while perl away (leaving intact 2.6) but i wiped out pip at the proces to. -- http://mail.python.org/mailman/listinfo/python-list Pip should be in your system's package manager. In Ubuntu it's available through sudo apt-get install python-pip. What are those development tools you speak of? Why would you uninstall perl? -- http://mail.python.org/mailman/listinfo/python-list
Re: Too many python installations. Should i remove them all and install the latest?
Τη Τρίτη, 4 Ιουνίου 2013 10:08:44 π.μ. UTC+3, ο χρήστης Fábio Santos έγραψε: Pip should be in your system's package manager. In Ubuntu it's available through sudo apt-get install python-pip. What are those development tools you speak of? Why would you uninstall perl? Sorry i meant Python, not Perl I'm using CentOS. So, i guess its something like 'yum install python-pip' i cannot find it, have searched it in variosu ways. -- http://mail.python.org/mailman/listinfo/python-list
Re: Too many python installations. Should i remove them all and install the latest?
On Jun 4, 5:11 pm, Νικόλαος Κούρας nikos.gr...@gmail.com wrote: So, i guess its something like 'yum install python-pip' i cannot find it, have searched it in variosu ways. If you're going to claim to have tried something, can you at least tell us what you tried? Because quelle surprise! the most obvious combination of search terms works: [plone@localhost]$ yum search python-pip ... python-pip.noarch : Pip installs packages. Python3 packages. An easy_install replacement If you're not seeing this then you've broken your package manager, possibly by overwriting the existing repositories with the new ones you've added. It's next to impossible to tell, however, because we don't have an access to what you mean by variosu ways. Expert tip: there's this AMAZING technology called Google, which if you visit their site, enter the cryptic incantation python pip centos, and click on *the very first link*, it actually provides you with explicit directions! What brave new world that etc! -- http://mail.python.org/mailman/listinfo/python-list
Re: PyWart: The problem with print
On Tue, Jun 4, 2013 at 11:37 AM, Rick Johnson rantingrickjohn...@gmail.com wrote: The print function is the very definition of a syntactic sugar. For example: print(some sting) is much more readable than: sys.stdout.write(some string+\n) ... Again, the removal of a print function (or print statement) will not prevent users from calling the write method on sys.stdout or sys.stderr (or ANY stream object for that matter!) And you could abolish ALL of the builtins by requiring that you import ctypes and implement them all yourself. That is not the point of the term. If print() is mere syntactic sugar, then everything is syntactic sugar for Brainf* code. The point of syntactic sugar is that there is a trivially-equivalent underlying interpretation. For instance, in C, array subscripting is trivially equivalent to addition and dereferencing: a[i] - *(a+i) This is syntactic sugar. The Python print() function does much more than write(), so it is NOT syntactic sugar. Many times you'll get a result (or an input) that you expect to be a Boolean, but instead is a string. A good example of poor coding is dialog box return values. Take your standard yes/no/cancel dialog, i would expect it to return True|False|None respectively, HOWEVER, some *idiot* decided to return the strings 'yes'|'no'|'cancel'. Why True|False|None? Why should they represent Yes|No|Cancel? Especially, *why None*? What has None to do with Cancel? However, with Python's implicit conversion to Boolean, the same conditional will ALWAYS be True: because any string that is not the null string is True (as far as Python is concerned). This is an example of Python devs breaking TWO Zens at once: explicit is better than implicit errors should NEVER pass silently Right, because it's Python's fault that you can't use implicit boolean conversion to sanely test for something that has three possible outcomes. I think there's something in the nature of a boolean test that makes this awkward, but I can't quite see it... hmm, some kind of integer issue, I think... Obviously you don't appreciate the value of explicit enough. if VALUE: is not explicit enough, however if bool(VALUE) or at least: if VALUE == True is explicit enough. Why? The 'if' implies a boolean context. In C, it's common to compare integers for nonzeroness with a bare if; it's also common, though far from universal, to compare strings for nullness - effectively equivalent to is not None. You don't need to be any more explicit than that. Granted, the definitions of truthiness differ from language to language. In C, a NULL pointer is false and any actual pointer is true, so an empty string is true (to the extent that C even has the concept of strings, but leave that aside). In Pike, any array is true, but the absence of an array can be indicated with (effectively) a null, whereas Python deems that an empty list is false. Still, most languages do have some system of coercion-to-boolean. (Notable exception: REXX. An IF statement will accept *only* the two permitted boolean values, anything else is an error.) However, if i choose to be explicit and use: if len(VALUE) 0: then the code will fail when it should: at the comparison line. Because any object that does not provide a __len__ method would cause Python to raise NameError. I thought you were dead against wasting CPU cycles! Your code here has to calculate the actual length of the object, then compare it with zero; the simple boolean check merely has to announce the presence or absence of content. This is a HUGE difference in performance, and you should totally optimize this down for the sake of that. Don't bother measuring it, this will make more difference to your code than replacing bubble sort with bogosort! ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
On Tue, Jun 4, 2013 at 4:28 PM, nagia.rets...@gmail.com wrote: Τη Τρίτη, 4 Ιουνίου 2013 1:46:53 π.μ. UTC+3, ο χρήστης Steven D'Aprano έγραψε: Not so -- it actually shows correctly, provided you use the right encoding. Tell your browser to view the page as UTF-8, and the file name is displayed correctly. I can't believe Chrome whcih by default uses utf8 chosed iso-8859-1 to presnt the filenames. What do you mean, by default uses UTF-8? Chrome uses whatever it's told. In this case, you have no encoding specified in the page, and your HTTP headers include: Content-Type:text/html;charset=ISO-8859-1 I wonder what effect that'll have... I wonder. Quit blaming Chrome for what's not its fault. (There's enough that is, but that's true of every browser.) ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Too many python installations. Should i remove them all and install the latest?
Τη Τρίτη, 4 Ιουνίου 2013 10:21:11 π.μ. UTC+3, ο χρήστης alex23 έγραψε: On Jun 4, 5:11 pm, Νικόλαος Κούρας nikos.gr...@gmail.com wrote: So, i guess its something like 'yum install python-pip' i cannot find it, have searched it in variosu ways. If you're going to claim to have tried something, can you at least tell us what you tried? Because quelle surprise! the most obvious combination of search terms works: Well, since you dough me here it is: ni...@superhost.gr [~]# yum search python-pip Loaded plugins: fastestmirror Determining fastest mirrors * base: mirror.netcologne.de * extras: mirror.optimate-server.de * updates: mirror.softaculous.com base | 3.7 kB 00:00 extras | 3.5 kB 00:00 updates | 3.4 kB 00:00 updates/primary_db | 2.6 MB 00:00 vz-base | 951 B 00:00 vz-base 3/3 vz-updates | 951 B 00:00 No Matches found ni...@superhost.gr [~]# -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
On Mon, 03 Jun 2013 23:28:21 -0700, nagia.retsina wrote: I can't believe Chrome whcih by default uses utf8 chosed iso-8859-1 to presnt the filenames. Chrome didn't choose ISO-8859-1, the server did; the HTTP response says: Content-Type: text/html;charset=ISO-8859-1 -- http://mail.python.org/mailman/listinfo/python-list
Re: Beginner question
eschneide...@comcast.net writes: Is there a more efficient way of doing this? Any help is gratly appreciated. Efficiency in a short program isn't a big thing. You have some pretty weird things in there, there's no need make single element tuples out of your strings and then putting those in a list. Just put the strings in a tuple and go. Likewise there's really no point in having while loops where you exit on the first round now is there? Just use an if. BTW, did I get the logic correctly, the end result is random? If true then the logic can be simplified greatly, you can just discard the user input and print a random choice of your three result strings... -- http://mail.python.org/mailman/listinfo/python-list
Re: Apache and suexec issue that wont let me run my python script
On Tue, Jun 4, 2013 at 2:45 PM, Michael Torrie torr...@gmail.com wrote: On 06/03/2013 05:33 PM, Carlos Nepomuceno wrote: I did a httpd 'make install' on CentOS 6 and it worked fine. Needed a few tweaks that I don't remember though. If you don't have any previous experience with Apache httpd settings I wouldn't try that on a production server. Precisely. Given his experience levels, installing httpd from source is recipe for disaster. He's now going to have to track security flaw reports manually, try to figure out which ones apply to him, and keep his apache up to date. I can't think of anything he'd need in Apache that's not in the CentOS packages. I've sys-admined for years and I've never ever needed an Apache outside out of the repos. Sometimes I needed other things I had to build from source, but never apache. Agreed. I'm a Debian guy rather than Red Hat, and by comparison Debian changes with every gust of wind, but the same applies. There's little reason to build most things from source; take advantage of the massive testing that's been done! Of course, there will be times when the version in the repo is just too old, but that's never been the case for me with Apache. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Beginner question
On Monday, June 3, 2013 11:46:03 PM UTC-7, Carlos Nepomuceno wrote: That doesn't even works because input() is the same as eval(raw_input()). So you'll get a NameError exception. I think you know that. Perhaps you mean raw_input() instead of input(). But the OP's code shows print() functions... which is not the habit of Python 2 programmers, even though it's legal code. And the OP says s/he's a beginning programmer... so why start learning Python 2 in 2013? Let me ask the OP, are you programming in Python 2 or Python 3? If the answer is indeed Python 3: raw_input() has been banished from Python 3, in favor of plain-old input(). -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
Τη Τρίτη, 4 Ιουνίου 2013 10:39:08 π.μ. UTC+3, ο χρήστης Nobody έγραψε: Chrome didn't choose ISO-8859-1, the server did; the HTTP response says: Content-Type: text/html;charset=ISO-8859-1 From where do you see this: i receivf this when trying from terminal: ni...@superhost.gr [~/www/data/apps]# wget -S -O - http://www.superhost.gr --2013-06-04 10:58:05-- http://www.superhost.gr/ Resolving www.superhost.gr... 82.211.30.133 Connecting to www.superhost.gr|82.211.30.133|:80... connected. HTTP request sent, awaiting response... HTTP/1.1 200 OK Server: ApacheBooster/1.6 Date: Tue, 04 Jun 2013 07:58:05 GMT Content-Type: text/html Connection: close Vary: Accept-Encoding !--: spam X-Cacheable: YES X-Varnish: 2000176616 2000176615 Via: 1.1 varnish age: 0 X-Cache: HIT X-Cache-Hits: 1 Length: unspecified [text/html] Saving to: βSTDOUTβ -- http://mail.python.org/mailman/listinfo/python-list
Re: Beginner question
On Tuesday, June 4, 2013 12:45:38 AM UTC-7, Anssi Saari wrote: BTW, did I get the logic correctly, the end result is random? You're right! I'm guessing that's not what the OP wants? -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
Τη Τρίτη, 4 Ιουνίου 2013 10:35:31 π.μ. UTC+3, ο χρήστης Chris Angelico έγραψε: I can't believe Chrome which by default uses 'utf-8' choosed 'iso-8859-1' to present the filenames. What do you mean, by default uses UTF-8? Chrome uses whatever it's told. In this case, you have no encoding specified in the page, and your HTTP headers include: Content-Type:text/html;charset=ISO-8859-1 From where do you see this Chris? I have an encoding specified in every cgi script i use by stating this command: print( '''Content-type: text/html; charset=utf-8\n''' ) ( That is a browser directive to display python script's output using 'utf-8' charset, that is why i wonder where you Nobody see greek-iso) and also i'm using this: sys.stdout = codecs.getwriter(utf-8)(sys.stdout.detach()) (not sure what exactly it does though, but if i remove it from my cgi scipts no python3 script runs, they are all die prematurely) -- http://mail.python.org/mailman/listinfo/python-list
RE: Beginner question
Date: Tue, 4 Jun 2013 00:53:04 -0700 Subject: Re: Beginner question From: john_lada...@sbcglobal.net To: python-list@python.org On Monday, June 3, 2013 11:46:03 PM UTC-7, Carlos Nepomuceno wrote: That doesn't even works because input() is the same as eval(raw_input()). So you'll get a NameError exception. I think you know that. Perhaps you mean raw_input() instead of input(). But the OP's code shows print() functions... which is not the habit of Python 2 programmers, even though it's legal code. And the OP says s/he's a beginning programmer... so why start learning Python 2 in 2013? Let me ask the OP, are you programming in Python 2 or Python 3? If the answer is indeed Python 3: raw_input() has been banished from Python 3, in favor of plain-old input(). Didn't know that. Thanks! -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Beginner question
On Tue, Jun 4, 2013 at 5:57 PM, John Ladasky john_lada...@sbcglobal.net wrote: On Tuesday, June 4, 2013 12:45:38 AM UTC-7, Anssi Saari wrote: BTW, did I get the logic correctly, the end result is random? You're right! I'm guessing that's not what the OP wants? I'm guessing that's exactly what the OP wants. This is a fairly classic programming puzzle; on the surface it appears that you have some influence on the outcome, but ultimately you're playing rock-paper-scissors with the Random Number God. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Too many python installations. Should i remove them all and install the latest?
Still can't find it: ni...@superhost.gr [~/www/data/apps]# yum search *pip* Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirror.netcologne.de * extras: mirror.optimate-server.de * updates: mirror.softaculous.com No Matches found ni...@superhost.gr [~/www/data/apps]# -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
On Mon, 03 Jun 2013 23:28:21 -0700, nagia.retsina wrote: ni...@superhost.gr [~]# locale LANG=en_US.UTF-8 [...] Okay, this is good. This means that your system is currently using UTF-8. Hese is also how the terminal presents my filenames. [...] ni...@superhost.gr [~]# ls -l www/data/apps/ total 368548 v2.4.msi -rw-r--r-- 1 nikos nikos 3511233 Jun 3 12:07 ΞΟ ΟΞ�\ Ο ΞΏΟ.mp3 Weirder and weirder. Please run these commands, and show what result they give: alias ls printf %q\\n *.mp3 ls -b *.mp3 I'll try renaming it via terminal too. f you want to see soemhtign else please ask me to show you Steven. 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 -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
Τη Τρίτη, 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]# ls -l *.mp3 -rw-r--r-- 1 nikos nikos 3511233 Jun 3 12:07 \305\365\367\336\ \364\357\365\ \311\347\363\357\375\375.mp3 -rw-r--r-- 1 nikos nikos 3511233 Jun 4 11:54 ΞΟ ΟΞ�\ Ο ΞΏΟ.mp3 ni...@superhost.gr [~/www/data/apps]# alias ls alias ls='/bin/ls $LS_OPTIONS' ni...@superhost.gr [~/www/data/apps]# printf %q\n\n *.mp3 $'\305\365\367\336 \364\357\365 \311\347\363\357\375\375.mp3'nn$'\316\225\317\205\317\207\316\256 \317\204\316\277\317\205 \316\231\316\267\317\203\316\277\317\215.mp3'nnni...@superhost.gr [~/www/data/apps]# ls -b *.mp3 \305\365\367\336\ \364\357\365\ \311\347\363\357\375\375.mp3 ΞΟ ΟΞ�\ Ο ΞΏΟ.mp3 please explain what this comamnd does. I deliberately placed the same .mp3 file twice. The first is after renaming it to greek chars and uploaded from within my Win8 machine via FileZilla to the webhost server The latter after renaming the file from within the remote linux machine. Seems that the way the system used to actually rename the file matters. 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' -- http://mail.python.org/mailman/listinfo/python-list
Re: Beginner question
On 06/03/2013 08:39 PM, eschneide...@comcast.net wrote: Is there a more efficient way of doing this? Any help is gratly appreciated. import random def partdeux(): print('''A man lunges at you with a knife! Do you DUCK or PARRY?''') option1=('duck') option2=('parry') optionsindex=[option1, option2] randomizer=random.choice(optionsindex) while randomizer==option1: if input() in option1: print('he tumbles over you') break else: print('he stabs you') break while randomizer==option2: if input() in option2: print('you trip him up') break else: print('he stabs you') break partdeux() Yes, you are making this much more complicated than necessary. It seems that what you are trying to do is input the option, then randomly print a success or failure message for that option. I suspect you didn't plan it, but it also prints the stab message for invalid entries. Like any program, it can be approached in many different ways. Here is one possibility. (Just the function def, add the import and function call as well. Also I am not adding any comments. See if you can follow the logic here yourself.) -- def partdeux(): print('A man lunges at you with a knife!') option = input('Do you DUCK or PARRY? ').lower() success = random.randint(0, 1) if success: if option == 'duck': print('He tumbles over you') return if option == 'parry': print('You trip him up') return print('He stabs you') BTW, ignore the response from Carlos. I can see from the print() functions in your original that you're using Python 3. His answer is only valid for Python 2. -=- Larry -=- -- http://mail.python.org/mailman/listinfo/python-list
Re: Beginner question
Chris Angelico wrote: On Tue, Jun 4, 2013 at 5:57 PM, John Ladasky john_lada...@sbcglobal.net wrote: On Tuesday, June 4, 2013 12:45:38 AM UTC-7, Anssi Saari wrote: BTW, did I get the logic correctly, the end result is random? You're right! I'm guessing that's not what the OP wants? I'm guessing that's exactly what the OP wants. This is a fairly classic programming puzzle; on the surface it appears that you have some influence on the outcome, but ultimately you're playing rock-paper-scissors with the Random Number God. As it is written, don't you always win if you hit enter? It may be the approved cheat code, though... OP: (some string) is not a tuple, it is the same as just some string therefore option1 = some string if input() in option1: print(yes) prints 'yes' if the user types in a substring of option1, and the shortest substring of any string is . For a single-item tuple the trailing comma is mandatory: (some string) # string 'some string' some string, # tuple ('some string',) (some string,) # tuple, parens added for clarity ('some string',) In general a tuple is consituted by the comma(s), not the parentheses: one, two ('one', 'two') -- http://mail.python.org/mailman/listinfo/python-list
Re: Too many python installations. Should i remove them all and install the latest?
Okey found it. since couldnt install pip i did: easy_install pymysql -- http://mail.python.org/mailman/listinfo/python-list
files.py failing when run via browser while properly executed via terminal
ni...@superhost.gr [~/www/cgi-bin]# ni...@superhost.gr [~/www/cgi-bin]# python Python 3.3.2 (default, Jun 3 2013, 16:18:05) [GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux Type help, copyright, credits or license for more information. exit() Okey after compiling from source python 3.3.2 and 'easy_install pymysql' now i'm receiving this error whiuch prohibit my files.py script to run. = ni...@superhost.gr [~/www/cgi-bin]# python files.py Error in sys.excepthook: ValueError: underlying buffer has been detached Original exception was: Traceback (most recent call last): File /usr/local/lib/python3.3/os.py, line 673, in __getitem__ value = self._data[self.encodekey(key)] KeyError: b'REMOTE_ADDR' During handling of the above exception, another exception occurred: Traceback (most recent call last): File files.py, line 17, in module host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] File /usr/local/lib/python3.3/os.py, line 676, in __getitem__ raise KeyError(key) KeyError: 'REMOTE_ADDR' ni...@superhost.gr [~/www/cgi-bin]# = host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] Is not the proeblem here becaus ei ahve the exact same statemnt inside metriets.py and pelatologio.py and they dont provide me an error. If i run the script from chrome as http://superhost.gr/cgi-bin/files.py i get na internal server error. But since it complained i switched the above host to host = nikos then run python files.py and it compiled properly with no error but via browser i receive internal server error agian. So since the script interprets okey i decided to tail the error log to see the live error messages when i call it via browser: ni...@superhost.gr [~/www/cgi-bin]# tail -F /usr/local/apache/logs/error_log [Tue Jun 04 13:02:37 2013] [error] [client 46.12.95.59] Error in sys.excepthook: [Tue Jun 04 13:02:37 2013] [error] [client 46.12.95.59] ValueError: underlying buffer has been detached [Tue Jun 04 13:02:37 2013] [error] [client 46.12.95.59] [Tue Jun 04 13:02:37 2013] [error] [client 46.12.95.59] Original exception was: [Tue Jun 04 13:02:37 2013] [error] [client 46.12.95.59] Traceback (most recent call last): [Tue Jun 04 13:02:37 2013] [error] [client 46.12.95.59] File files.py, line 67, in module [Tue Jun 04 13:02:37 2013] [error] [client 46.12.95.59] cur.execute('''SELECT url FROM files WHERE url = %s''', (fullpath,) ) [Tue Jun 04 13:02:37 2013] [error] [client 46.12.95.59] File /usr/local/lib/python3.3/site-packages/PyMySQL3-0.5-py3.3.egg/pymysql/cursors.py, line 108, in execute [Tue Jun 04 13:02:37 2013] [error] [client 46.12.95.59] query = query.encode(charset) [Tue Jun 04 13:02:37 2013] [error] [client 46.12.95.59] UnicodeEncodeError: 'utf-8' codec can't encode character '\\udcce' in position 61: surrogates not allowed [Tue Jun 04 13:02:37 2013] [error] [client 46.12.95.59] Premature end of script headers: files.py [Tue Jun 04 13:02:37 2013] [error] [client 46.12.95.59] File does not exist: /home/nikos/public_html/500.shtml I tried anything i can think of, hti sis beyond me, so please shed some light. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: Apache and suexec issue that wont let me run my python script
I think i'll do a chmod 666 /var/log/httpd/suexec.log and see if the error goes away. I think what the problem is, i have the owner and group as root:root with read/write permissions, but apache is likely owned by something else (www:www or apache:webservd). So either i'll have to change the group ownership of the log file to the group apache is running as or change the log file to world read/write, which isn't safe since other people log into the box, but is generally harmless i think with log files. Checking the permissions of /var/log/httpd directory itself: ni...@superhost.gr [~/www/cgi-bin]# ls -ld /var/log/httpd/ drwx-- 2 root root 4096 Jun 1 02:52 /var/log/httpd// Is that a problem? http != Apache ? i'm still confused about what is: '/var/log/httpd' and what is '/usr/local/Apache' Is seems like this is the same service runnign twice under different names. -- http://mail.python.org/mailman/listinfo/python-list
Re: Apache and suexec issue that wont let me run my python script
I just tried out those: root@nikos [~]# ls -l /var/log/httpd/suexec.log -rw-rw-r-- 1 root root 0 Jun 1 02:52 /var/log/httpd/suexec.log root@nikos [~]# ls -l /usr/local/apache/logs/suexec_log -rw-rw-r-- 1 root apache 532667 Jun 4 13:11 /usr/local/apache/logs/suexec_log root@nikos [~]# chown root:apache /var/log/httpd/suexec.log root@nikos [~]# ls -l /var/log/httpd/suexec.log -rw-rw-r-- 1 root apache 0 Jun 1 02:52 /var/log/httpd/suexec.log but i'm not usre if they solve the problem or why there are 2 suexec.log files. -- http://mail.python.org/mailman/listinfo/python-list
Re: Apache and suexec issue that wont let me run my python script
On Jun 4, 2013, at 6:12 AM, Νικόλαος Κούρας nikos.gr...@gmail.com wrote: Checking the permissions of /var/log/httpd directory itself: ni...@superhost.gr [~/www/cgi-bin]# ls -ld /var/log/httpd/ drwx-- 2 root root 4096 Jun 1 02:52 /var/log/httpd// Is that a problem? http != Apache ? Yes, httpd is Apache, or at least part of Apache. i'm still confused about what is: '/var/log/httpd' and what is '/usr/local/Apache' Is seems like this is the same service runnign twice under different names. Not really. Unix unlike some other OSes, separates your data from your applications. That's one reason, when Apple designed Mac OS X, you can re-install Mac OS X over your current installation, and not lose any data. Your user data is separate from the OS data. The /Usr tree is considered read-only. In theory nothing should write to that folder, unless you are installing Unix tools. Please note, it's not read only in the OS, yes, it does require super user rights, but that tree is not read only. The /Var tree is where the OS writes data to. For example, Log files, temporary work files, etc. I hope this clears some of this up. If I have made any mistakes here, please feel free to politely correct me |-) - Benjamin -- http://mail.python.org/mailman/listinfo/python-list
Re: Apache and suexec issue that wont let me run my python script
root@nikos [/home/nikos/www/cgi-bin]# chmod 755 /var/log/httpd/suexec.log root@nikos [/home/nikos/www/cgi-bin]# ls -l /var/log/httpd/suexec.log -rwxr-xr-x 1 root apache 0 Jun 1 02:52 /var/log/httpd/suexec.log* root@nikos [/home/nikos/www/cgi-bin]# chmod 755 /usr/local/apache/logs/error_log root@nikos [/home/nikos/www/cgi-bin]# ls -l /usr/local/apache/logs/error_log -rwxr-xr-x 1 root root 32414017 Jun 4 13:51 /usr/local/apache/logs/error_log* root@nikos [/home/nikos/www/cgi-bin]# chown root:apache /usr/local/apache/logs/error_log root@nikos [/home/nikos/www/cgi-bin]# ls -l /usr/local/apache/logs/error_log -rwxr-xr-x 1 root apache 32414017 Jun 4 13:51 /usr/local/apache/logs/error_log* root@nikos [/home/nikos/www/cgi-bin]# Now the error i get whn trying to run my scgi script via browser is root@nikos [/home/nikos/www/cgi-bin]# [Tue Jun 04 13:55:26 2013] [error] [client 46.12.95.59] suexec failure: could not open log file [Tue Jun 04 13:55:26 2013] [error] [client 46.12.95.59] fopen: Permission denied [Tue Jun 04 13:55:26 2013] [error] [client 46.12.95.59] Premature end of script headers: koukos.py [Tue Jun 04 13:55:26 2013] [error] [client 46.12.95.59] File does not exist: /home/nikos/public_html/500.shtml I just don't get it. I chmod'ed i chown'ed Why still doesn't work? -- http://mail.python.org/mailman/listinfo/python-list
RE: Apache and suexec issue that wont let me run my python script
send the output of the following command: ps aux|grep httpd Date: Tue, 4 Jun 2013 03:56:19 -0700 Subject: Re: Apache and suexec issue that wont let me run my python script From: nikos.gr...@gmail.com To: python-list@python.org root@nikos [/home/nikos/www/cgi-bin]# chmod 755 /var/log/httpd/suexec.log root@nikos [/home/nikos/www/cgi-bin]# ls -l /var/log/httpd/suexec.log -rwxr-xr-x 1 root apache 0 Jun 1 02:52 /var/log/httpd/suexec.log* root@nikos [/home/nikos/www/cgi-bin]# chmod 755 /usr/local/apache/logs/error_log root@nikos [/home/nikos/www/cgi-bin]# ls -l /usr/local/apache/logs/error_log -rwxr-xr-x 1 root root 32414017 Jun 4 13:51 /usr/local/apache/logs/error_log* root@nikos [/home/nikos/www/cgi-bin]# chown root:apache /usr/local/apache/logs/error_log root@nikos [/home/nikos/www/cgi-bin]# ls -l /usr/local/apache/logs/error_log -rwxr-xr-x 1 root apache 32414017 Jun 4 13:51 /usr/local/apache/logs/error_log* root@nikos [/home/nikos/www/cgi-bin]# Now the error i get whn trying to run my scgi script via browser is root@nikos [/home/nikos/www/cgi-bin]# [Tue Jun 04 13:55:26 2013] [error] [client 46.12.95.59] suexec failure: could not open log file [Tue Jun 04 13:55:26 2013] [error] [client 46.12.95.59] fopen: Permission denied [Tue Jun 04 13:55:26 2013] [error] [client 46.12.95.59] Premature end of script headers: koukos.py [Tue Jun 04 13:55:26 2013] [error] [client 46.12.95.59] File does not exist: /home/nikos/public_html/500.shtml I just don't get it. I chmod'ed i chown'ed Why still doesn't work? -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Apache and suexec issue that wont let me run my python script
Τη Τρίτη, 4 Ιουνίου 2013 2:04:36 μ.μ. UTC+3, ο χρήστης Carlos Nepomuceno έγραψε: send the output of the following command: ps aux|grep httpd root@nikos [/home/nikos/www/data/apps]# ps aux | grep httpd root 19194 0.0 0.2 74224 4440 ?Ss Jul13 0:00 /usr/local/apache/bin/httpd -k start -DSSL root 19201 0.0 0.1 74136 2576 ?SJul13 0:00 /usr/local/apache/bin/httpd -k start -DSSL nobody 19202 0.0 0.2 74492 4320 ?SJul13 0:00 /usr/local/apache/bin/httpd -k start -DSSL nobody 19203 0.0 0.2 74488 4304 ?SJul13 0:00 /usr/local/apache/bin/httpd -k start -DSSL nobody 19204 0.0 0.2 74488 4352 ?SJul13 0:00 /usr/local/apache/bin/httpd -k start -DSSL nobody 19205 0.0 0.2 74492 4336 ?SJul13 0:00 /usr/local/apache/bin/httpd -k start -DSSL nobody 19206 0.0 0.2 74544 4328 ?SJul13 0:00 /usr/local/apache/bin/httpd -k start -DSSL nobody 19215 0.0 0.2 74492 4300 ?SJul13 0:00 /usr/local/apache/bin/httpd -k start -DSSL nobody 20170 0.0 0.2 74356 4264 ?SJul13 0:00 /usr/local/apache/bin/httpd -k start -DSSL root 20860 0.0 0.0 103240 856 pts/2S+ Jul13 0:00 grep httpd root@nikos [/home/nikos/www/data/apps]# -- http://mail.python.org/mailman/listinfo/python-list
RE: Beginner question
Started answering... now I'm asking! lol I've tried to use dict() to create a dictionary to use like the switch statement providing variable names instead of literals, such as: a='A' b='B' {a:0,b:1}#here the variables are resolved {'A': 0, 'B': 1} That's ok! But if I use dict() declaration: dict(a=0,b=1) {'a': 0, 'b': 1}#here variable names are taken as literals What's going on? Is there a way to make dict() to resolve the variables? -- http://mail.python.org/mailman/listinfo/python-list
Re: files.py failing when run via browser while properly executed via terminal
i tried somehtign else too. uploaded 1.mp3 and 1.exe from windows 8 via FileZilla to linux webhost and then renamed them both to Greek letters so that the renaming take place from within the CentOS and after that i tried: http://superhost.gr/cgi-bin/files.py Guess what? Still same error :( [Tue Jun 04 14:21:05 2013] [error] [client 46.12.95.59] Error in sys.excepthook: [Tue Jun 04 14:21:05 2013] [error] [client 46.12.95.59] ValueError: underlying buffer has been detached [Tue Jun 04 14:21:05 2013] [error] [client 46.12.95.59] [Tue Jun 04 14:21:05 2013] [error] [client 46.12.95.59] Original exception was: [Tue Jun 04 14:21:05 2013] [error] [client 46.12.95.59] Traceback (most recent call last): [Tue Jun 04 14:21:05 2013] [error] [client 46.12.95.59] File files.py, line 67, in module [Tue Jun 04 14:21:05 2013] [error] [client 46.12.95.59] cur.execute('''SELECT url FROM files WHERE url = %s''', (fullpath,) ) [Tue Jun 04 14:21:05 2013] [error] [client 46.12.95.59] File /usr/local/lib/python3.3/site-packages/PyMySQL3-0.5-py3.3.egg/pymysql/cursors.py, line 108, in execute [Tue Jun 04 14:21:05 2013] [error] [client 46.12.95.59] query = query.encode(charset) [Tue Jun 04 14:21:05 2013] [error] [client 46.12.95.59] UnicodeEncodeError: 'utf-8' codec can't encode character '\\udcd3' in position 61: surrogates not allowed [Tue Jun 04 14:21:05 2013] [error] [client 46.12.95.59] Premature end of script headers: files.py [Tue Jun 04 14:21:05 2013] [error] [client 46.12.95.59] File does not exist: /home/nikos/public_html/500.shtml What the hell is it with these Greek filenames, why everyhting breaks? -- http://mail.python.org/mailman/listinfo/python-list
Re: Too many python installations. Should i remove them all and install the latest?
On 4 Jun 2013 10:54, Νικόλαος Κούρας nikos.gr...@gmail.com wrote: Okey found it. since couldnt install pip i did: easy_install pymysql It is not the recommended way to install pip, but you can ironically easy_install pip -- http://mail.python.org/mailman/listinfo/python-list
RE: Apache and suexec issue that wont let me run my python script
The httpd processes are run by user 'nobody'. You have to change your httpd.conf to assign the correct user or change the owner of the log file to nobody. On httpd.conf look for the following directives: User root Group root Date: Tue, 4 Jun 2013 04:09:44 -0700 Subject: Re: Apache and suexec issue that wont let me run my python script From: nikos.gr...@gmail.com To: python-list@python.org Τη Τρίτη, 4 Ιουνίου 2013 2:04:36 μ.μ. UTC+3, ο χρήστης Carlos Nepomuceno έγραψε: send the output of the following command: ps aux|grep httpd root@nikos [/home/nikos/www/data/apps]# ps aux | grep httpd root 19194 0.0 0.2 74224 4440 ?Ss Jul13 0:00 /usr/local/apache/bin/httpd -k start -DSSL root 19201 0.0 0.1 74136 2576 ?SJul13 0:00 /usr/local/apache/bin/httpd -k start -DSSL nobody 19202 0.0 0.2 74492 4320 ?SJul13 0:00 /usr/local/apache/bin/httpd -k start -DSSL nobody 19203 0.0 0.2 74488 4304 ?SJul13 0:00 /usr/local/apache/bin/httpd -k start -DSSL nobody 19204 0.0 0.2 74488 4352 ?SJul13 0:00 /usr/local/apache/bin/httpd -k start -DSSL nobody 19205 0.0 0.2 74492 4336 ?SJul13 0:00 /usr/local/apache/bin/httpd -k start -DSSL nobody 19206 0.0 0.2 74544 4328 ?SJul13 0:00 /usr/local/apache/bin/httpd -k start -DSSL nobody 19215 0.0 0.2 74492 4300 ?SJul13 0:00 /usr/local/apache/bin/httpd -k start -DSSL nobody 20170 0.0 0.2 74356 4264 ?SJul13 0:00 /usr/local/apache/bin/httpd -k start -DSSL root 20860 0.0 0.0 103240 856 pts/2S+ Jul13 0:00 grep httpd root@nikos [/home/nikos/www/data/apps]# -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Apache and suexec issue that wont let me run my python script
root@nikos [/home/nikos/www/data/apps]# ls -l /usr/local/apache/logs/error_log -rwxr-xr-x 1 root apache 32447472 Jun 4 14:36 /usr/local/apache/logs/error_log* root@nikos [/home/nikos/www/data/apps]# chown nobody:apache /usr/local/apache/logs/error_log root@nikos [/home/nikos/www/data/apps]# ls -l /usr/local/apache/logs/error_log -rwxr-xr-x 1 nobody apache 32447472 Jun 4 14:36 /usr/local/apache/logs/error_log* still the same error. -- http://mail.python.org/mailman/listinfo/python-list
Re: Too many python installations. Should i remove them all and install the latest?
On 4 Jun 2013 12:26, Fábio Santos fabiosantos...@gmail.com wrote: On 4 Jun 2013 10:54, Νικόλαος Κούρας nikos.gr...@gmail.com wrote: Okey found it. since couldnt install pip i did: easy_install pymysql It is not the recommended way to install pip, but you can ironically easy_install pip Sorry for double posting but my favorite web host has a lot of pythons. It is very handy. -- http://mail.python.org/mailman/listinfo/python-list
RE: Beginner question
On 4 Jun 2013 12:28, Carlos Nepomuceno carlosnepomuc...@outlook.com wrote: Started answering... now I'm asking! lol I've tried to use dict() to create a dictionary to use like the switch statement providing variable names instead of literals, such as: a='A' b='B' {a:0,b:1}#here the variables are resolved {'A': 0, 'B': 1} That's ok! But if I use dict() declaration: dict(a=0,b=1) {'a': 0, 'b': 1}#here variable names are taken as literals What's going on? Is there a way to make dict() to resolve the variables? Well yes. dict(**{a:0,b:1}) The dict() constructor makes a dictionary from keyword arguments. So you just have to feed it keyword arguments using **. And if you're in a bad day, dict(**locals()) -- http://mail.python.org/mailman/listinfo/python-list
Re: Apache and suexec issue that wont let me run my python script
Τη Τρίτη, 4 Ιουνίου 2013 2:27:25 μ.μ. UTC+3, ο χρήστης Carlos Nepomuceno έγραψε: The httpd processes are run by user 'nobody'. You have to change your httpd.conf to assign the correct user or change the owner of the log file to nobody. On httpd.conf look for the following directives: User root Group root Why some httpd run as root(first two) and the rest as nobody? What is user 'nobody' anyways? root@nikos [/home/nikos/www/data/apps]# nano /usr/local/apache/conf/httpd.conf root@nikos [/home/nikos/www/data/apps]# cat /usr/local/apache/conf/httpd.conf | grep 'User root' root@nikos [/home/nikos/www/data/apps]# cat /usr/local/apache/conf/httpd.conf | grep 'user root' root@nikos [/home/nikos/www/data/apps]# cat /usr/local/apache/conf/httpd.conf | grep 'group root' root@nikos [/home/nikos/www/data/apps]# cat /usr/local/apache/conf/httpd.conf | grep 'Group root' Doesn't seem to be there. -- http://mail.python.org/mailman/listinfo/python-list
RE: Beginner question
On 4 Jun 2013 12:28, Carlos Nepomuceno carlosnepomuc...@outlook.com wrote: [...] What's going on? Is there a way to make dict() to resolve the variables? Well yes. dict(**{a:0,b:1}) The dict() constructor makes a dictionary from keyword arguments. So you just have to feed it keyword arguments using **. And if you're in a bad day, dict(**locals()) That's exactly the same! dict(**{a:0,b:1})=={a:0,b:1} True Are there any benefits from using dict() instead of {}? -- http://mail.python.org/mailman/listinfo/python-list
RE: Apache and suexec issue that wont let me run my python script
Post your httpd.conf to pastebin and send us the link... Date: Tue, 4 Jun 2013 04:38:44 -0700 Subject: Re: Apache and suexec issue that wont let me run my python script From: nikos.gr...@gmail.com To: python-list@python.org root@nikos [/home/nikos/www/data/apps]# ls -l /usr/local/apache/logs/error_log -rwxr-xr-x 1 root apache 32447472 Jun 4 14:36 /usr/local/apache/logs/error_log* root@nikos [/home/nikos/www/data/apps]# chown nobody:apache /usr/local/apache/logs/error_log root@nikos [/home/nikos/www/data/apps]# ls -l /usr/local/apache/logs/error_log -rwxr-xr-x 1 nobody apache 32447472 Jun 4 14:36 /usr/local/apache/logs/error_log* still the same error. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
RE: Apache and suexec issue that wont let me run my python script
Date: Tue, 4 Jun 2013 04:36:06 -0700 Subject: Re: Apache and suexec issue that wont let me run my python script From: nikos.gr...@gmail.com To: python-list@python.org Τη Τρίτη, 4 Ιουνίου 2013 2:27:25 μ.μ. UTC+3, ο χρήστης Carlos Nepomuceno έγραψε: The httpd processes are run by user 'nobody'. You have to change your httpd.conf to assign the correct user or change the owner of the log file to nobody. On httpd.conf look for the following directives: User root Group root Why some httpd run as root(first two) and the rest as nobody? The root processes are run by init during startup. The nobody processes are started by the first httpd processes based on httpd.conf settings. What is user 'nobody' anyways? Just a user with no shell access. root@nikos [/home/nikos/www/data/apps]# nano /usr/local/apache/conf/httpd.conf root@nikos [/home/nikos/www/data/apps]# cat /usr/local/apache/conf/httpd.conf | grep 'User root' root@nikos [/home/nikos/www/data/apps]# cat /usr/local/apache/conf/httpd.conf | grep 'user root' root@nikos [/home/nikos/www/data/apps]# cat /usr/local/apache/conf/httpd.conf | grep 'group root' root@nikos [/home/nikos/www/data/apps]# cat /usr/local/apache/conf/httpd.conf | grep 'Group root' Doesn't seem to be there. You have to edit httpd.conf and change the User and Group directives. They currently are set to nobody, so you have to look for ' User nobody' and ' Group nobody'. Take care while editing httpd.conf. Make a backup copy just in case. ;) -- http://mail.python.org/mailman/listinfo/python-list
Re: Apache and suexec issue that wont let me run my python script
Τη Τρίτη, 4 Ιουνίου 2013 2:42:52 μ.μ. UTC+3, ο χρήστης Carlos Nepomuceno έγραψε: Post your httpd.conf to pastebin and send us the link... Here it is: http://pastebin.com/kMT2BZp1 -- http://mail.python.org/mailman/listinfo/python-list
ANN: Version 0.1.1 of sarge (a subprocess wrapper library) has been released.
Version 0.1.1 of Sarge, a cross-platform library which wraps the subprocess module in the standard library, has been released. What changed? - - Added the ability to scan for specific patterns in subprocess output streams. - Added convenience methods to operate on wrapped subprocesses. - Exceptions which occur while spawning subprocesses are now propagated. - Fixed issues #2, #3, and #4. - Improved shell_shlex resilience with Unicode on 2.x. - Added get_stdout, get_stderr and get_both for when subprocess output is not expected to be voluminous. - Added an internal lock to serialise access to shared data. - Added tests to cover added functionality and reported issues. - Added numerous documentation updates. What does Sarge do? --- Sarge tries to make interfacing with external programs from your Python applications easier than just using subprocess alone. Sarge offers the following features: * A simple way to run command lines which allows a rich subset of Bash- style shell command syntax, but parsed and run by sarge so that you can run on Windows without cygwin (subject to having those commands available): from sarge import capture_stdout p = capture_stdout('echo foo | cat; echo bar') for line in p.stdout: print(repr(line)) ... 'foo\n' 'bar\n' * The ability to format shell commands with placeholders, such that variables are quoted to prevent shell injection attacks. * The ability to capture output streams without requiring you to program your own threads. You just use a Capture object and then you can read from it as and when you want. Advantages over subprocess --- Sarge offers the following benefits compared to using subprocess: * The API is very simple. * It's easier to use command pipelines - using subprocess out of the box often leads to deadlocks because pipe buffers get filled up. * It would be nice to use Bash-style pipe syntax on Windows, but Windows shells don't support some of the syntax which is useful, like , ||, | and so on. Sarge gives you that functionality on Windows, without cygwin. * Sometimes, subprocess.Popen.communicate() is not flexible enough for one's needs - for example, when one needs to process output a line at a time without buffering the entire output in memory. * It's desirable to avoid shell injection problems by having the ability to quote command arguments safely. * subprocess allows you to let stderr be the same as stdout, but not the other way around - and sometimes, you need to do that. Python version and platform compatibility - Sarge is intended to be used on any Python version = 2.6 and is tested on Python versions 2.6, 2.7, 3.1, 3.2 and 3.3 on Linux, Windows, and Mac OS X (not all versions are tested on all platforms, but sarge is expected to work correctly on all these versions on all these platforms). Finding out more You can read the documentation at http://sarge.readthedocs.org/ There's a lot more information, with examples, than I can put into this post. You can install Sarge using pip install sarge to try it out. The project is hosted on BitBucket at https://bitbucket.org/vinay.sajip/sarge/ And you can leave feedback on the issue tracker there. I hope you find Sarge useful! Regards, Vinay Sajip -- http://mail.python.org/mailman/listinfo/python-list
RE: Apache and suexec issue that wont let me run my python script
Date: Tue, 4 Jun 2013 04:48:34 -0700 Subject: Re: Apache and suexec issue that wont let me run my python script From: nikos.gr...@gmail.com To: python-list@python.org Τη Τρίτη, 4 Ιουνίου 2013 2:42:52 μ.μ. UTC+3, ο χρήστης Carlos Nepomuceno έγραψε: Post your httpd.conf to pastebin and send us the link... Here it is: http://pastebin.com/kMT2BZp1 -- http://mail.python.org/mailman/listinfo/python-list Your httpd.conf is automatically generated by cPanel. Take a look: # Defined in /var/cpanel/cpanel.config: apache_portListen 0.0.0.0:82User nobodyGroup nobodyExtendedStatus OnServerAdmin nikos.gr33k@gmail.comServerName nikos.superhost.grLogLevel warn That means you have to change the settings on cPanel not directly editing httpd.conf. I don't use cPanel so I can't help you on that. Good luck! -- http://mail.python.org/mailman/listinfo/python-list
RE: Beginner question
On 4 Jun 2013 12:57, Carlos Nepomuceno carlosnepomuc...@outlook.com wrote: On 4 Jun 2013 12:28, Carlos Nepomuceno carlosnepomuc...@outlook.com wrote: [...] What's going on? Is there a way to make dict() to resolve the variables? Well yes. dict(**{a:0,b:1}) The dict() constructor makes a dictionary from keyword arguments. So you just have to feed it keyword arguments using **. And if you're in a bad day, dict(**locals()) That's exactly the same! dict(**{a:0,b:1})=={a:0,b:1} True Are there any benefits from using dict() instead of {}? Other than being able to create a dict from a list of tuples, and copying a dict using dict(anotherdict.items()), not that I know of. -- http://mail.python.org/mailman/listinfo/python-list
Re: PyWart: The problem with print
On 2 juin, 20:09, Rick Johnson rantingrickjohn...@gmail.com wrote: I never purposely inject ANY superfluous cycles in my code except in the case of testing or development. To me it's about professionalism. Let's consider a thought exercise shall we? The flexible string representation is the perfect example of this lack of professionalism. Wrong by design, a non understanding of the mathematical logic, of the coding of characters, of Unicode and of the usage of characters (everything is tight together). How is is possible to arrive to such a situation ? The answer if far beyond my understanding (although I have my opinion on the subject). jmf -- http://mail.python.org/mailman/listinfo/python-list
Re: Beginner question
On Tue, 04 Jun 2013 14:53:29 +0300, Carlos Nepomuceno wrote: That's exactly the same! dict(**{a:0,b:1})=={a:0,b:1} True Of course it is. Isn't that what you wanted? It's also a waste of time, because you create a dict literal using {}, then unpack it into keyword arguments, then call dict() to create a new dict with the same content. Rather like doing this: n = int(str(42)) only even more expensive. Are there any benefits from using dict() instead of {}? Of course there are. {} can be used for creating dict literals, which means you are limited to key/values that you explicitly include. dict(), on the other hand, has a rich set of constructor APIs: py help(dict) Help on class dict in module builtins: class dict(object) | dict() - new empty dictionary | dict(mapping) - new dictionary initialized from a mapping object's | (key, value) pairs | dict(iterable) - new dictionary initialized as if via: | d = {} | for k, v in iterable: | d[k] = v | dict(**kwargs) - new dictionary initialized with the name=value pairs | in the keyword argument list. For example: dict(one=1, two=2) py dict(zip('abcd', range(4)), x=23, y=42, z=999) {'a': 0, 'c': 2, 'b': 1, 'd': 3, 'y': 42, 'x': 23, 'z': 999} Try doing that with {} alone! -- Steven -- http://mail.python.org/mailman/listinfo/python-list
RE: Beginner question
From: steve+comp.lang.pyt...@pearwood.info Subject: Re: Beginner question Date: Tue, 4 Jun 2013 12:25:27 + To: python-list@python.org On Tue, 04 Jun 2013 14:53:29 +0300, Carlos Nepomuceno wrote: That's exactly the same! dict(**{a:0,b:1})=={a:0,b:1} True Of course it is. Isn't that what you wanted? Indeed! But that form isn't economically viable as you noted. It's also a waste of time, because you create a dict literal using {}, then unpack it into keyword arguments, then call dict() to create a new dict with the same content. Rather like doing this: n = int(str(42)) only even more expensive. Are there any benefits from using dict() instead of {}? Of course there are. {} can be used for creating dict literals, which means you are limited to key/values that you explicitly include. dict(), on the other hand, has a rich set of constructor APIs: py help(dict) Help on class dict in module builtins: class dict(object) | dict() - new empty dictionary | dict(mapping) - new dictionary initialized from a mapping object's | (key, value) pairs | dict(iterable) - new dictionary initialized as if via: | d = {} | for k, v in iterable: | d[k] = v | dict(**kwargs) - new dictionary initialized with the name=value pairs | in the keyword argument list. For example: dict(one=1, two=2) py dict(zip('abcd', range(4)), x=23, y=42, z=999) {'a': 0, 'c': 2, 'b': 1, 'd': 3, 'y': 42, 'x': 23, 'z': 999} Awesome! Now I can do it just like that: dict([(chr(ord('a')+x),x) for x in range(2)]) {'a': 0, 'b': 1} Thanks a lot! ;) -- http://mail.python.org/mailman/listinfo/python-list
Re: Beginner question
On Tue, 04 Jun 2013 14:23:39 +0300, Carlos Nepomuceno wrote: Started answering... now I'm asking! lol I've tried to use dict() to create a dictionary to use like the switch statement providing variable names instead of literals, such as: a='A' b='B' {a:0,b:1}#here the variables are resolved {'A': 0, 'B': 1} That's ok! But if I use dict() declaration: dict(a=0,b=1) {'a': 0, 'b': 1}#here variable names are taken as literals What's going on? Is there a way to make dict() to resolve the variables? This is by design. You're calling a function, dict(), and like all functions, code like: func(name=value) provides a *keyword argument*, where the argument is called name and the argument's value is as given. dict is no different from any other function, it has no superpowers, keyword arguments are still keyword arguments. In this case, there is no simple way to use the dict() function[1] the way you want. You could build up a string and then call eval(): s = dict(%s=0, %s=1) % (a, b) d = eval(s) but that's slow and inconvenient and dangerous if your data is untrusted. So in this specific case, you should stick to the {} method. [1] Technically it's a type, not a function, but the difference makes no difference here. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
RE: Beginner question
Awesome! Now I can do it just like that: dict([(chr(ord('a')+x),x) for x in range(2)]) {'a': 0, 'b': 1} Thanks a lot! ;) Or dict((c, i) for (i, c) in enumerate('ab')) But at this point you could just use a dict comprehension. {c: i for i, c in enumerate('ab')} -- http://mail.python.org/mailman/listinfo/python-list
RE: Beginner question
From: steve+comp.lang.pyt...@pearwood.info Subject: Re: Beginner question Date: Tue, 4 Jun 2013 12:35:59 + To: python-list@python.org On Tue, 04 Jun 2013 14:23:39 +0300, Carlos Nepomuceno wrote: Started answering... now I'm asking! lol I've tried to use dict() to create a dictionary to use like the switch statement providing variable names instead of literals, such as: a='A' b='B' {a:0,b:1}#here the variables are resolved {'A': 0, 'B': 1} That's ok! But if I use dict() declaration: dict(a=0,b=1) {'a': 0, 'b': 1}#here variable names are taken as literals What's going on? Is there a way to make dict() to resolve the variables? This is by design. You're calling a function, dict(), and like all functions, code like: func(name=value) provides a *keyword argument*, where the argument is called name and the argument's value is as given. dict is no different from any other function, it has no superpowers, keyword arguments are still keyword arguments. In this case, there is no simple way to use the dict() function[1] the way you want. You could build up a string and then call eval(): s = dict(%s=0, %s=1) % (a, b) d = eval(s) but that's slow and inconvenient and dangerous if your data is untrusted. So in this specific case, you should stick to the {} method. [1] Technically it's a type, not a function, but the difference makes no difference here. -- Steven It's superclear now! You're an excelent teacher! Can you explain me the difference of the type and function you've just mentioned? -- http://mail.python.org/mailman/listinfo/python-list
Re: Apache and suexec issue that wont let me run my python script
Τη Τρίτη, 4 Ιουνίου 2013 3:11:18 μ.μ. UTC+3, ο χρήστης Carlos Nepomuceno έγραψε: Date: Tue, 4 Jun 2013 04:48:34 -0700 Subject: Re: Apache and suexec issue that wont let me run my python script From: nikos...@gmail.com To: pytho...@python.org Τη Τρίτη, 4 Ιουνίου 2013 2:42:52 μ.μ. UTC+3, ο χρήστης Carlos Nepomuceno έγραψε: Post your httpd.conf to pastebin and send us the link... Here it is: http://pastebin.com/kMT2BZp1 -- http://mail.python.org/mailman/listinfo/python-list Your httpd.conf is automatically generated by cPanel. Take a look: # Defined in /var/cpanel/cpanel.config: apache_port Listen 0.0.0.0:82 User nobody Group nobody ExtendedStatus On ServerAdmin nikos...@gmail.com ServerName nikos.superhost.gr LogLevel warn That means you have to change the settings on cPanel not directly editing httpd.conf. I don't use cPanel so I can't help you on that. Good luck! Since, i'm root i will open the file and alter the user nobody to root. Can't i? Also about the suexec.log since i made it 755 why still suexec complain that it cannot open it? -- http://mail.python.org/mailman/listinfo/python-list
Re: Apache and suexec issue that wont let me run my python script
root@nikos [~]# nano /usr/local/apache/conf/httpd.conf and altering user nobody to user root. root@nikos [~]# service httpd restart [Tue Jun 04 15:56:42 2013] [warn] module rpaf_module is already loaded, skipping Syntax error on line 175 of /usr/local/apache/conf/httpd.conf: Error:\tApache has not been designed to serve pages while\n\trunning as root. There are known race conditions that\n\twill allow any local user to read any file on the system.\n\tIf you still desire to serve pages as root then\n\tadd -DBIG_SECURITY_HOLE to the CFLAGS env variable\n\tand then rebuild the server.\n\tIt is strongly suggested that you instead modify the User\n\tdirective in your httpd.conf file to list a non-root\n\tuser.\n root@nikos [~]# What can i do? -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
On Tue, 04 Jun 2013 00:58:42 -0700, Νικόλαος Κούρας wrote: Τη Τρίτη, 4 Ιουνίου 2013 10:39:08 π.μ. UTC+3, ο χρήστης Nobody έγραψε: Chrome didn't choose ISO-8859-1, the server did; the HTTP response says: Content-Type: text/html;charset=ISO-8859-1 From where do you see this $ wget -S -O - http://superhost.gr/data/apps/ --2013-06-04 14:00:10-- http://superhost.gr/data/apps/ Resolving superhost.gr... 82.211.30.133 Connecting to superhost.gr|82.211.30.133|:80... connected. HTTP request sent, awaiting response... HTTP/1.1 200 OK Server: ApacheBooster/1.6 Date: Tue, 04 Jun 2013 13:00:19 GMT Content-Type: text/html;charset=ISO-8859-1 Transfer-Encoding: chunked Connection: keep-alive Vary: Accept-Encoding X-Cacheable: YES X-Varnish: 2000177813 Via: 1.1 varnish age: 0 X-Cache: MISS -- http://mail.python.org/mailman/listinfo/python-list
Re: Apache and suexec issue that wont let me run my python script
On Tue, Jun 4, 2013 at 10:57 PM, Νικόλαος Κούρας nikos.gr...@gmail.com wrote: root@nikos [~]# nano /usr/local/apache/conf/httpd.conf and altering user nobody to user root. root@nikos [~]# service httpd restart [Tue Jun 04 15:56:42 2013] [warn] module rpaf_module is already loaded, skipping Syntax error on line 175 of /usr/local/apache/conf/httpd.conf: Error:\tApache has not been designed to serve pages while\n\trunning as root. There are known race conditions that\n\twill allow any local user to read any file on the system.\n\tIf you still desire to serve pages as root then\n\tadd -DBIG_SECURITY_HOLE to the CFLAGS env variable\n\tand then rebuild the server.\n\tIt is strongly suggested that you instead modify the User\n\tdirective in your httpd.conf file to list a non-root\n\tuser.\n root@nikos [~]# What can i do? Don't do that. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
RE: Apache and suexec issue that wont let me run my python script
Date: Tue, 4 Jun 2013 05:57:54 -0700 Subject: Re: Apache and suexec issue that wont let me run my python script From: nikos.gr...@gmail.com To: python-list@python.org root@nikos [~]# nano /usr/local/apache/conf/httpd.conf and altering user nobody to user root. root@nikos [~]# service httpd restart [Tue Jun 04 15:56:42 2013] [warn] module rpaf_module is already loaded, skipping Syntax error on line 175 of /usr/local/apache/conf/httpd.conf: Error:\tApache has not been designed to serve pages while\n\trunning as root. There are known race conditions that\n\twill allow any local user to read any file on the system.\n\tIf you still desire to serve pages as root then\n\tadd -DBIG_SECURITY_HOLE to the CFLAGS env variable\n\tand then rebuild the server.\n\tIt is strongly suggested that you instead modify the User\n\tdirective in your httpd.conf file to list a non-root\n\tuser.\n root@nikos [~]# What can i do? You don't need to run httpd as root. In fact it's risky. You can use another user with less privileges to run it like nobody or something else you see fit. I don't think the suggestion to rebuild the server is good, but I don't know how cPanel works so it's just a guess. -- http://mail.python.org/mailman/listinfo/python-list
Re: Beginner question
In article ikkdnevcx7wymjdmnz2dnuvz_ssdn...@giganews.com, Larry Hudson org...@yahoo.com wrote: def partdeux(): print('A man lunges at you with a knife!') option = input('Do you DUCK or PARRY? ').lower() success = random.randint(0, 1) if success: if option == 'duck': print('He tumbles over you') return if option == 'parry': print('You trip him up') return print('He stabs you') I'm going to suggest another possible way to organize this. I'm not claiming it's necessarily better, but as this is a learning exercise, it's worth exploring. Get rid of all the conditional logic and make this purely table-driven: responses = {(0, 'duck'): He tumbles over you, (0, 'parry'): You trip him up, (1, 'duck'): He stabs you, (1, 'parry'): He stabs you, } and then def partdeux(): print('A man lunges at you with a knife!') option = input('Do you DUCK or PARRY? ').lower() success = random.randint(0, 1) print responses[(success, option)] Consider what happens when the game evolves to the point where you have four options (DUCK, PARRY, RETREAT, FEINT), multiple levels of success, and modifiers for which hand you and/or your opponent are holding your weapons in? Trying to cover all that with nested logic will quickly drive you insane. -- http://mail.python.org/mailman/listinfo/python-list
Re: Apache and suexec issue that wont let me run my python script
Τη Τρίτη, 4 Ιουνίου 2013 4:10:58 μ.μ. UTC+3, ο χρήστης Chris Angelico έγραψε: On Tue, Jun 4, 2013 at 10:57 PM, Νικόλαος Κούρας nikos.gr...@gmail.com wrote: root@nikos [~]# nano /usr/local/apache/conf/httpd.conf and altering user nobody to user root. root@nikos [~]# service httpd restart [Tue Jun 04 15:56:42 2013] [warn] module rpaf_module is already loaded, skipping Syntax error on line 175 of /usr/local/apache/conf/httpd.conf: Error:\tApache has not been designed to serve pages while\n\trunning as root. There are known race conditions that\n\twill allow any local user to read any file on the system.\n\tIf you still desire to serve pages as root then\n\tadd -DBIG_SECURITY_HOLE to the CFLAGS env variable\n\tand then rebuild the server.\n\tIt is strongly suggested that you instead modify the User\n\tdirective in your httpd.conf file to list a non-root\n\tuser.\n Don't do that. Well i can understand its dangerous but it doesnt also let me. So that leaved me the tampering of the log files. root@nikos [~]# chmod 755 /var/log/httpd/error_log root@nikos [~]# chown nobody:nobody /var/log/httpd/error_log root@nikos [~]# chmod 755 /usr/local/apache/logs/error_log root@nikos [~]# chown nobody:nobody /usr/local/apache/logs/error_log BUT just my luck. root@nikos [~]# [Tue Jun 04 16:16:21 2013] [error] [client 46.12.95.59] suexec failure: could not open log file [Tue Jun 04 16:16:21 2013] [error] [client 46.12.95.59] fopen: Permission denied [Tue Jun 04 16:16:21 2013] [error] [client 46.12.95.59] Premature end of script headers: koukos.py [Tue Jun 04 16:16:21 2013] [error] [client 46.12.95.59] File does not exist: /home/nikos/public_html/500.shtml [Tue Jun 04 16:16:24 2013] [error] [client 46.12.95.59] suexec failure: could not open log file [Tue Jun 04 16:16:24 2013] [error] [client 46.12.95.59] fopen: Permission denied [Tue Jun 04 16:16:24 2013] [error] [client 46.12.95.59] Premature end of script headers: koukos.py I DONT KNOW WHAT ELSE TO TRY PLEASE HELP ILL TRY ANYTHING YOU SAY. -- http://mail.python.org/mailman/listinfo/python-list
Re: PyWart: The problem with print
On Jun 4, 5:23 pm, jmfauth wxjmfa...@gmail.com wrote: On 2 juin, 20:09, Rick Johnson rantingrickjohn...@gmail.com wrote: I never purposely inject ANY superfluous cycles in my code except in the case of testing or development. To me it's about professionalism. Let's consider a thought exercise shall we? The flexible string representation is the perfect example of this lack of professionalism. Wrong by design, a non understanding of the mathematical logic, of the coding of characters, of Unicode and of the usage of characters (everything is tight together). How is is possible to arrive to such a situation ? The answer if far beyond my understanding (although I have my opinion on the subject). jmf The Clash of the Titans Lé jmf chârgeth with mightƴ might And le Mond underneath trembleth Now RR mounts his sturdy steed And the windmill yonder turneth -- http://mail.python.org/mailman/listinfo/python-list
Re: PyWart: The problem with print
On 04/06/2013 14:29, rusi wrote: On Jun 4, 5:23 pm, jmfauth wxjmfa...@gmail.com wrote: On 2 juin, 20:09, Rick Johnson rantingrickjohn...@gmail.com wrote: I never purposely inject ANY superfluous cycles in my code except in the case of testing or development. To me it's about professionalism. Let's consider a thought exercise shall we? The flexible string representation is the perfect example of this lack of professionalism. Wrong by design, a non understanding of the mathematical logic, of the coding of characters, of Unicode and of the usage of characters (everything is tight together). How is is possible to arrive to such a situation ? The answer if far beyond my understanding (although I have my opinion on the subject). jmf The Clash of the Titans Lé jmf chârgeth with mightƴ might And le Mond underneath trembleth Now RR mounts his sturdy steed And the windmill yonder turneth +1 funniest poem of the week :) -- 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: Changing filenames from Greeklish = Greek (subprocess complain)
Τη Τρίτη, 4 Ιουνίου 2013 4:01:48 μ.μ. UTC+3, ο χρήστης Nobody έγραψε: On Tue, 04 Jun 2013 00:58:42 -0700, Νικόλαος Κούρας wrote: Τη Τρίτη, 4 Ιουνίου 2013 10:39:08 π.μ. UTC+3, ο χρήστης Nobody έγραψε: Chrome didn't choose ISO-8859-1, the server did; the HTTP response says: Content-Type: text/html;charset=ISO-8859-1 From where do you see this $ wget -S -O - http://superhost.gr/data/apps/ --2013-06-04 14:00:10-- http://superhost.gr/data/apps/ Resolving superhost.gr... 82.211.30.133 Connecting to superhost.gr|82.211.30.133|:80... connected. HTTP request sent, awaiting response... HTTP/1.1 200 OK Server: ApacheBooster/1.6 Date: Tue, 04 Jun 2013 13:00:19 GMT Content-Type: text/html;charset=ISO-8859-1 Transfer-Encoding: chunked Connection: keep-alive Vary: Accept-Encoding X-Cacheable: YES X-Varnish: 2000177813 Via: 1.1 varnish age: 0 X-Cache: MISS Ah, you were talking for the '/www/data/apps subfolder', yes indeed, i though you were talking about superhost.gr. That how Apache chooses to show them, but this is not so much important because visitors wont enter directly that page, but they will have a chnace to get those files from within http://superhost.gr/cgi-bin/files.py which in turn gives me this: [Tue Jun 04 16:36:09 2013] [error] [client 46.12.95.59] Error in sys.excepthook: [Tue Jun 04 16:36:09 2013] [error] [client 46.12.95.59] ValueError: underlying buffer has been detached [Tue Jun 04 16:36:09 2013] [error] [client 46.12.95.59] [Tue Jun 04 16:36:09 2013] [error] [client 46.12.95.59] Original exception was: [Tue Jun 04 16:36:09 2013] [error] [client 46.12.95.59] Traceback (most recent call last): [Tue Jun 04 16:36:09 2013] [error] [client 46.12.95.59] File files.py, line 67, in module [Tue Jun 04 16:36:09 2013] [error] [client 46.12.95.59] cur.execute('''SELECT url FROM files WHERE url = %s''', (fullpath,) ) [Tue Jun 04 16:36:09 2013] [error] [client 46.12.95.59] File /usr/local/lib/python3.3/site-packages/PyMySQL3-0.5-py3.3.egg/pymysql/cursors.py, line 108, in execute [Tue Jun 04 16:36:09 2013] [error] [client 46.12.95.59] query = query.encode(charset) [Tue Jun 04 16:36:09 2013] [error] [client 46.12.95.59] UnicodeEncodeError: 'utf-8' codec can't encode character '\\udcd3' in position 61: surrogates not allowed [Tue Jun 04 16:36:09 2013] [error] [client 46.12.95.59] Premature end of script headers: files.py :( -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get an integer from a sequence of bytes
On 2013-06-03, Dan Stromberg drsali...@gmail.com wrote: On Mon, Jun 3, 2013 at 7:31 AM, Grant Edwards invalid@invalid.invalidwrote: That's a common assumption, but historically, a byte was merely the smallest addressable unit of memory. The size of a byte on widely used used CPUs ranged from 4 bits to 60 bits. Quoting from http://en.wikipedia.org/wiki/Byte The size of the byte has historically been hardware dependent and no definitive standards existed that mandated the size. That's why IEEE standards always use the word octet when referring a value containing 8 bits. When I was a Freshman in college, I used a CDC Cyber a lot; it had 6 bit bytes and 60 bit words. This was in 1985. But you couldn't address individual 6-bit hextets in memory could you? My recollection is that incrementing a memory address got you the next 60-bit chunk -- that means that by the older terminology a byte was 60 bits. A character was 6 bits, and a single register or memory location could hold 6 characters. Today though, it would be difficult to sell a conventional (Von Neumann) computer that didn't have 8 bit bytes. There are tons (as in millions of units per month) of CPUs still being sold in the DSP market with 16, 20, 24, and 32 bit bytes. (When writing C on a TMS320Cxx CPU sizeof (char) == sizeof (int) == sizeof (long) == sizeof (float) == sizeof (double) == 1. They all contain 32 bits. Quantum computers would still sell if they were odd this way - they're going to be really different anyway. -- Grant Edwards grant.b.edwardsYow! Either CONFESS now or at we go to PEOPLE'S COURT!! gmail.com -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get an integer from a sequence of bytes
On 2013-06-03, Carlos Nepomuceno carlosnepomuc...@outlook.com wrote: Date: Mon, 3 Jun 2013 15:41:41 -0700 Subject: Re: How to get an integer from a sequence of bytes From: drsali...@gmail.com To: python-list@python.org [...] Today though, it would be difficult to sell a conventional (Von Neumann) computer that didn't have 8 bit bytes. Quantum computers would still sell if they were odd this way - they're going to be really different anyway. Nowadays it would be a hard task to find a Von Neumann architecture machine. Most of current CPUs are variants of the Harvard architecture: they separate instructions from data at the cache level. VN designs are still very common in smaller CPUs (embedded stuff). Even modern desktop CPUs are logically still Von Neumann designs from the programmer's point of view (there's only a single address space for both data and instructions). The fact that there are two sparate caches is almost entirely hidden from the user. If you start to do stuff like write self-modifying code, then _may_ start having to worry about cache coherency. -- Grant Edwards grant.b.edwardsYow! I request a weekend in at Havana with Phil Silvers! gmail.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
Steven said: It looks like your client is ignoring the charset header, and interpreting the bytes as Latin-1 when they are actually ISO-8859-7. py s = 'Eυχή του Ιησού.mp3' py print(s.encode('ISO-8859-7').decode('latin-1')) Eõ÷Þ ôïõ Éçóïý.mp3 which matches what you see. If you can manually tell your client to use ISO-8859-7, you should see it correctly. I think this is the case too Steven, but it suprises me to see that Chrome ignores the charset header. Actually when i told explicitly Chrome to display everythign as utf-8 it presented the filaname properly. py print(s.encode('ISO-8859-7').decode('latin-1')) Why you are encoding the 's' string to greek-iso? Isn't it set by itself in greek-iso since it uses greek-iso lettering? I think you are very close to solution but i cannot clearly see it yet. -- http://mail.python.org/mailman/listinfo/python-list
RE: How to get an integer from a sequence of bytes
From: invalid@invalid.invalid Subject: Re: How to get an integer from a sequence of bytes Date: Tue, 4 Jun 2013 13:42:46 + To: python-list@python.org [...] VN designs are still very common in smaller CPUs (embedded stuff). DSPs perhaps... not CPUs. Even ARMs are Harvard variants. Even modern desktop CPUs are logically still Von Neumann designs from the programmer's point of view (there's only a single address space for both data and instructions). The fact that there are two sparate caches is almost entirely hidden from the user. If you start to do stuff like write self-modifying code, then _may_ start having to worry about cache coherency. Code/data separation isn't the only aspect. VN architecture is totally serial, even for RAM. It's been a while since we've got into the multi-core, multipath world. Even in embedded devices. -- Grant Edwards grant.b.edwardsYow! I request a weekend in at Havana with Phil Silvers! gmail.com -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
I' just tried to implment your idea by correcting file names as: # Compute a set of current fullpaths fullpaths = set() path = /home/nikos/www/data/apps/ for root, dirs, files in os.walk(path): for fullpath in files: fullpaths.add( os.path.join(root, fullpath) ) # 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('ISO-8859-7').decode('latin-1'), ) data = cur.fetchone()#URL is unique, so should only be one This gave me this error: root@nikos [~]# [Tue Jun 04 16:55:51 2013] [error] [client 46.12.95.59] File files.py, line 68 [Tue Jun 04 16:55:51 2013] [error] [client 46.12.95.59] data = cur.fetchone()#URL is unique, so should only be one [Tue Jun 04 16:55:51 2013] [error] [client 46.12.95.59]^ [Tue Jun 04 16:55:51 2013] [error] [client 46.12.95.59] SyntaxError: invalid syntax [Tue Jun 04 16:55:51 2013] [error] [client 46.12.95.59] Premature end of script headers: files.py [Tue Jun 04 16:55:51 2013] [error] [client 46.12.95.59] File does not exist: /home/nikos/public_html/500.shtml It seem that this approach overcame the error, won't you agree? But i see no syntax error in the exact follow up line. data = cur.fetchone()#URL is unique, so should only be one -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
On 04/06/2013 14:57, Νικόλαος Κούρας wrote: I' just tried to implment your idea by correcting file names as: # Compute a set of current fullpaths fullpaths = set() path = /home/nikos/www/data/apps/ for root, dirs, files in os.walk(path): for fullpath in files: fullpaths.add( os.path.join(root, fullpath) ) # 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('ISO-8859-7').decode('latin-1'), ) data = cur.fetchone()#URL is unique, so should only be one This gave me this error: root@nikos [~]# [Tue Jun 04 16:55:51 2013] [error] [client 46.12.95.59] File files.py, line 68 [Tue Jun 04 16:55:51 2013] [error] [client 46.12.95.59] data = cur.fetchone()#URL is unique, so should only be one [Tue Jun 04 16:55:51 2013] [error] [client 46.12.95.59]^ [Tue Jun 04 16:55:51 2013] [error] [client 46.12.95.59] SyntaxError: invalid syntax [Tue Jun 04 16:55:51 2013] [error] [client 46.12.95.59] Premature end of script headers: files.py [Tue Jun 04 16:55:51 2013] [error] [client 46.12.95.59] File does not exist: /home/nikos/public_html/500.shtml It seem that this approach overcame the error, won't you agree? But i see no syntax error in the exact follow up line. data = cur.fetchone()#URL is unique, so should only be one The syntax error is often in the preceeding line, typically because you're missed a closing bracket. -- 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: Changing filenames from Greeklish = Greek (subprocess complain)
No, brackets are all there. Just tried: # Compute a set of current fullpaths fullpaths = set() path = /home/nikos/www/data/apps/ for root, dirs, files in os.walk(path): for fullpath in files: fullpaths.add( os.path.join(root, fullpath) ) print (fullpath ) print (fullpath.encode('iso-8859-7').decode('latin-1') ) sys.exit(0) = root@nikos [~]# [Tue Jun 04 17:16:18 2013] [error] [client 46.12.95.59] Error in sys.excepthook: [Tue Jun 04 17:16:18 2013] [error] [client 46.12.95.59] ValueError: underlying buffer has been detached [Tue Jun 04 17:16:18 2013] [error] [client 46.12.95.59] [Tue Jun 04 17:16:18 2013] [error] [client 46.12.95.59] Original exception was: [Tue Jun 04 17:16:18 2013] [error] [client 46.12.95.59] Traceback (most recent call last): [Tue Jun 04 17:16:18 2013] [error] [client 46.12.95.59] File files.py, line 61, in module [Tue Jun 04 17:16:18 2013] [error] [client 46.12.95.59] print (fullpath ) [Tue Jun 04 17:16:18 2013] [error] [client 46.12.95.59] File /usr/local/lib/python3.3/codecs.py, line 355, in write [Tue Jun 04 17:16:18 2013] [error] [client 46.12.95.59] data, consumed = self.encode(object, self.errors) [Tue Jun 04 17:16:18 2013] [error] [client 46.12.95.59] UnicodeEncodeError: 'utf-8' codec can't encode character '\\udcc5' in position 0: surrogates not allowed [Tue Jun 04 17:16:18 2013] [error] [client 46.12.95.59] Premature end of script headers: files.py [Tue Jun 04 17:16:18 2013] [error] [client 46.12.95.59] File does not exist: /home/nikos/public_html/500.shtml = What are these 'surrogate' things? -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
Know i tries the decode thing the moment the string join. for root, dirs, files in os.walk(path): for fullpath in files: fullpaths.add( os.path.join(root, fullpath).decode('latin-1') ) But the /www/data/apps folder have inside them both english greek filenames It's clear to me now that this is a matter of encoding-decoding issue. But encode to what and decode to what other? How can the script encode and decode properly when it has mix of both english and weird-greek endoing filanems inside its corresponding folder? -- http://mail.python.org/mailman/listinfo/python-list
Re: Apache and suexec issue that wont let me run my python script
On Tue, Jun 4, 2013 at 11:17 PM, Νικόλαος Κούρας nikos.gr...@gmail.com wrote: I DONT KNOW WHAT ELSE TO TRY PLEASE HELP ILL TRY ANYTHING YOU SAY. You should try power surging your drivers. Have you got a spare power cord? ChrisA [1] http://www.oocities.org/timessquare/4753/bofh.htm -- http://mail.python.org/mailman/listinfo/python-list
Re: Too many python installations. Should i remove them all and install the latest?
On 06/04/2013 01:39 AM, Νικόλαος Κούρας wrote: Well, since you dough me here it is: Did you even bother to google it? If you did, you'd find that python-pip is available in a semi-official repository called EPEL. Just about every RHEL and CentOS install should have EPEL installed. Now it's pip for Python 2.6 of course. If you need python 3.3, there is a repo out there (third-party of course) that google can help you find. -- http://mail.python.org/mailman/listinfo/python-list
Re: Apache and suexec issue that wont let me run my python script
Τη Τρίτη, 4 Ιουνίου 2013 5:33:03 μ.μ. UTC+3, ο χρήστης Chris Angelico έγραψε: I DONT KNOW WHAT ELSE TO TRY PLEASE HELP ILL TRY ANYTHING YOU SAY. You should try power surging your drivers. Have you got a spare power cord? Jokes are funny, but its over a week now the script is correct and the damn suexec thing doesnt let me do my job. -- http://mail.python.org/mailman/listinfo/python-list
Re: Apache and suexec issue that wont let me run my python script
On 04/06/2013 15:40, Νικόλαος Κούρας wrote: Τη Τρίτη, 4 Ιουνίου 2013 5:33:03 μ.μ. UTC+3, ο χρήστης Chris Angelico έγραψε: I DONT KNOW WHAT ELSE TO TRY PLEASE HELP ILL TRY ANYTHING YOU SAY. You should try power surging your drivers. Have you got a spare power cord? Jokes are funny, but its over a week now the script is correct and the damn suexec thing doesnt let me do my job. I don't know much about the Python suexec module, can you please explain where it's documented. Or is suexec nothing to do with Python? -- 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: Apache and suexec issue that wont let me run my python script
On Tue, Jun 4, 2013 at 4:49 PM, Mark Lawrence breamore...@yahoo.co.uk wrote: I don't know much about the Python suexec module, can you please explain where it's documented. Or is suexec nothing to do with Python? From Wikipedia: Apache suEXEC is a feature of the Apache Web server. It allows users to run CGI and SSI applications as a different user - normally, all web server processes run as the default web server user (often wwwrun, Apache or nobody). In other words: Nikolaos is trying to do something HORRIBLY WRONG (just like always). The proper way would be to run the python scripts through WSGI as the standard nobody user. Or do proper file permissions. And WSGI should be used through something intelligent (flask/pyramid/…) --- OT START --- On Tue, Jun 4, 2013 at 4:33 PM, Chris Angelico ros...@gmail.com wrote: You should try power surging your drivers. Have you got a spare power cord? ChrisA [1] http://www.oocities.org/timessquare/4753/bofh.htm -- http://mail.python.org/mailman/listinfo/python-list Please link and read at the BOFH’s page. [0] is the page and [1] is this exact story. [0]: http://bofh.ntk.net/BOFH/index.php [1]: http://bofh.ntk.net/BOFH//bastard07.php -- Kwpolska http://kwpolska.tk | GPG KEY: 5EAAEA16 stop html mail| always bottom-post http://asciiribbon.org| http://caliburn.nl/topposting.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing filenames from Greeklish = Greek (subprocess complain)
On 06/04/2013 08:18 AM, Νικόλαος Κούρας wrote: No, brackets are all there. Just tried: # Compute a set of current fullpaths fullpaths = set() path = /home/nikos/www/data/apps/ for root, dirs, files in os.walk(path): for fullpath in files: fullpaths.add( os.path.join(root, fullpath) ) print (fullpath ) print (fullpath.encode('iso-8859-7').decode('latin-1') ) This is wrong. You are converting unicode to iso-8859-7 bytes, then trying to convert those bytes back to unicode by pretending they are latin-1 bytes. Even if this worked it will generate garbage. What are these 'surrogate' things? It means that when you tried to decode greek bytes using latin-1, there were some invalid unicode letters created (which is expected, since the bytes are not latin-1, they are iso-8859-7!). If you want the browser to use a particular encoding scheme (utf-8), then you have to print out an HTTP header before you start printing your other HTML data: print(Content-Type: text/html;charset=UTF-8\r\n) print(\r\n) print(html data goes here) -- http://mail.python.org/mailman/listinfo/python-list
Re: Apache and suexec issue that wont let me run my python script
On Wed, Jun 5, 2013 at 1:06 AM, Chris “Kwpolska” Warrick kwpol...@gmail.com wrote: [1] http://www.oocities.org/timessquare/4753/bofh.htm -- http://mail.python.org/mailman/listinfo/python-list Please link and read at the BOFH’s page. [0] is the page and [1] is this exact story. [0]: http://bofh.ntk.net/BOFH/index.php [1]: http://bofh.ntk.net/BOFH//bastard07.php Hrm. I went poking on ntk.net but couldn't find it, so I posted a different link rather than go with no link. Thanks for finding the official page, that's what I'd prefer normally. I think SimonT mucked up something a while ago and lost himself a pile of search engine rank. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: lstrip problem - beginner question
On Tuesday, June 4, 2013 11:21:53 AM UTC-4, mstagliamonte wrote: Hi everyone, I am a beginner in python and trying to find my way through... :) I am writing a script to get numbers from the headers of a text file. If the header is something like: h01 = ('scaffold_1') I just use: h01.lstrip('scaffold_') and this returns me with '1' But, if the header is: h02: ('contig-100_1') if I use: h02.lstrip('contig-100_') this returns me with: '' ...basically nothing. What surprises me is that if I do in this other way: h02b = h02.lstrip('contig-100') I get h02b = ('_1') and subsequently: h02b.lstrip('_') returns me with: '1' which is what I wanted! Why is this happening? What am I missing? Thanks for your help and attention Max -- http://mail.python.org/mailman/listinfo/python-list
lstrip problem - beginner question
Hi everyone, I am a beginner in python and trying to find my way through... :) I am writing a script to get numbers from the headers of a text file. If the header is something like: h01 = ('scaffold_1') I just use: h01.lstrip('scaffold_') and this returns me '1' But, if the header is: h02: ('contig-100_0') if I use: h02.lstrip('contig-100_') this returns me with: '' ...basically nothing. What surprises me is that if I do in this other way: h02b = h02.lstrip('contig-100') I get h02b = ('_1') and subsequently: h02b.lstrip('_') returns me with: '1' which is what I wanted! Why is this happening? What am I missing? Thanks for your help and attention Max -- http://mail.python.org/mailman/listinfo/python-list
Re: Apache and suexec issue that wont let me run my python script
On Tue, Jun 4, 2013 at 11:11 AM, Chris Angelico ros...@gmail.com wrote: On Wed, Jun 5, 2013 at 1:06 AM, Chris “Kwpolska” Warrick kwpol...@gmail.com wrote: [1] http://www.oocities.org/timessquare/4753/bofh.htm -- http://mail.python.org/mailman/listinfo/python-list Please link and read at the BOFH’s page. [0] is the page and [1] is this exact story. [0]: http://bofh.ntk.net/BOFH/index.php [1]: http://bofh.ntk.net/BOFH//bastard07.php Hrm. I went poking on ntk.net but couldn't find it, so I posted a different link rather than go with no link. Thanks for finding the official page, that's what I'd prefer normally. I think SimonT mucked up something a while ago and lost himself a pile of search engine rank. ChrisA -- http://mail.python.org/mailman/listinfo/python-list reading this thread is like slowing down to see the car wreck on the other side of the highway. I think I feel bad for the people who are paying to host their stuff on the OP server. But maybe they get what they deserve. -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: lstrip problem - beginner question
On Tuesday, June 4, 2013 11:21:53 AM UTC-4, mstagliamonte wrote: Hi everyone, I am a beginner in python and trying to find my way through... :) I am writing a script to get numbers from the headers of a text file. If the header is something like: h01 = ('scaffold_1') I just use: h01.lstrip('scaffold_') and this returns me '1' But, if the header is: h02: ('contig-100_0') if I use: h02.lstrip('contig-100_') this returns me with: '' ...basically nothing. What surprises me is that if I do in this other way: h02b = h02.lstrip('contig-100') I get h02b = ('_1') and subsequently: h02b.lstrip('_') returns me with: '1' which is what I wanted! Why is this happening? What am I missing? Thanks for your help and attention Max edit: h02: ('contig-100_1') -- http://mail.python.org/mailman/listinfo/python-list
Re: lstrip problem - beginner question
On Tuesday, June 4, 2013 11:21:53 AM UTC-4, mstagliamonte wrote: Hi everyone, I am a beginner in python and trying to find my way through... :) I am writing a script to get numbers from the headers of a text file. If the header is something like: h01 = ('scaffold_1') I just use: h01.lstrip('scaffold_') and this returns me '1' But, if the header is: h02: ('contig-100_0') if I use: h02.lstrip('contig-100_') this returns me with: '' ...basically nothing. What surprises me is that if I do in this other way: h02b = h02.lstrip('contig-100') I get h02b = ('_1') and subsequently: h02b.lstrip('_') returns me with: '1' which is what I wanted! Why is this happening? What am I missing? Thanks for your help and attention Max edit: h02= ('contig-100_1') -- http://mail.python.org/mailman/listinfo/python-list
Re: lstrip problem - beginner question
On Tuesday, June 4, 2013 11:21:53 AM UTC-4, mstagliamonte wrote: Hi everyone, I am a beginner in python and trying to find my way through... :) I am writing a script to get numbers from the headers of a text file. If the header is something like: h01 = ('scaffold_1') I just use: h01.lstrip('scaffold_') and this returns me '1' But, if the header is: h02: ('contig-100_0') if I use: h02.lstrip('contig-100_') this returns me with: '' ...basically nothing. What surprises me is that if I do in this other way: h02b = h02.lstrip('contig-100') I get h02b = ('_1') and subsequently: h02b.lstrip('_') returns me with: '1' which is what I wanted! Why is this happening? What am I missing? Thanks for your help and attention Max edit: h02= ('contig-100_1') -- http://mail.python.org/mailman/listinfo/python-list
Re: Bools and explicitness [was Re: PyWart: The problem with print]
On Tuesday, June 4, 2013 12:39:59 AM UTC-5, Steven D'Aprano wrote: On Mon, 03 Jun 2013 18:37:24 -0700, Rick Johnson wrote: Consider a simple thought experiment. Suppose we start with a sequence of if statements that begin simple and get more complicated: if a == 1: ... if a == 1 and b 2*c: ... if a == 1 and b 2*c or d%4 == 1: ... if a == 1 and b 2*c or d%4 == 1 and not (d**3//7)%3 == 0: ... I don't believe that any of these tests are improved by adding an extraneous == True at the end: if (a == 1) == True: ... if (a == 1 and b 2*c) == True: ... if (a == 1 and b 2*c or d%4 == 1) == True: ... if (a == 1 and b 2*c or d%4 == 1 and not (d**3//7)%3 == 0) == True: ... And i agree! You are misunderstanding my very valid point. Post-fixing a == True when truth testing a *real* Boolean (psst: that's a True or False object) is superfluous, I'm referring to truth testing non-Boolean values. So with that in mind, the following is acceptably explicit enough for me: a = True if a: do_something() However, since Python allows implicit conversion to Boolean for ALL types, unless we know for sure, beyond any reasonable doubt, that the variable we are truth testing is pointing to a True or False object, we are taking too many chances and will eventually create subtle bugs. a = if a: do_something() When if write code that truth tests, i expect that the value i'm testing is a True or False object, not an empty list that *magically* converts to False when i place an if in front of it, or a list with more members that magically converts to True when i place an if in front of it. This implicit conversion seems like a good idea at first, and i was caught up in the hype myself for some time: Hey, i can save a few keystrokes, AWESOME!. However, i can tell you with certainty that this implicit conversion is folly. It is my firm belief that truth testing a value that is not a Boolean should raise an exception. If you want to convert a type to Boolean then pass it to the bool function: lst = [1,2,3] if bool(lst): do_something This would be explicit enough If you are unfamiliar with Python, then you have to learn what the semantics of if lst means. Just as you would have to learn what if len(lst) 0 means. Again, i understand the folly of implicit Boolean conversion just fine. I prefer to be explicit at the cost of a few keystrokes: if len(lst) 0: This line of code is problematic, for various reasons: - you're making assumptions about the object which are unnecessary; - which breaks duck-typing; - and risks doing too much work, or failing altogether. You're looking up the length of the lst object, but you don't really care about the length. Yes i do care about the length or i would not have asked. I'm asking Python to tell me if the iterable has members, amd if it does, i want to execute a block of code, if it does not, i want to do nothing. But i'm also informing the reader of my source code that the symbol i am truth testing is expected to be an iterable with a __len__ method. if lst does not give me the same answer (or imply the same meaning to a reader), it merely tells me that the implict conversion has resulted in a True value, but what if the lst symbol is pointing to a string? Then i will falsely believe i have a list with members when i actually have a string with length greater than zero. You only care about whether there is something there or not, whether lst is empty or not. It makes no difference whether lst contains one item or one hundred million items, and yet you're asking to count them all. Only to throw that count away immediately! I agree. Summing the list members just to guarantee that the iterable has members is foolish, however, python gives me no other choice IF i want to be explicit enough. In a properly designed language, the base iterable object would supply a hasLength or hasMembers method that would return a much faster check of: try: iterable[0] except IndexError: return False else: return True That check would guarantee the iterable contained at least one member without counting them all. Looking at the length of a built-in list is cheap, but why assume it is a built-in list? Perhaps it is a linked list where counting the items requires a slow O(N) traversal of the entire list. Or some kind of lazy sequence that has no way of counting the items remaining, but knows whether it is exhausted or not. Yes, but the problem is not my approach, rather the lack of proper language design (my apologizes to the anointed one. ;-) The Python way is to duck-type, and to let the lst object decide for itself whether it's empty or not: if lst: ... not to make assumptions about the specific type and performance of the object. Well Steven, in the real world sometimes you have no other choice. I don't have time to read and comprehend thousands of
Re: lstrip problem - beginner question
On 4 Jun 2013 16:34, mstagliamonte madmax...@yahoo.it wrote: On Tuesday, June 4, 2013 11:21:53 AM UTC-4, mstagliamonte wrote: Hi everyone, I am a beginner in python and trying to find my way through... :) I am writing a script to get numbers from the headers of a text file. If the header is something like: h01 = ('scaffold_1') I just use: h01.lstrip('scaffold_') and this returns me '1' But, if the header is: h02: ('contig-100_0') if I use: h02.lstrip('contig-100_') this returns me with: '' ...basically nothing. What surprises me is that if I do in this other way: h02b = h02.lstrip('contig-100') I get h02b = ('_1') and subsequently: h02b.lstrip('_') returns me with: '1' which is what I wanted! Why is this happening? What am I missing? Thanks for your help and attention Max edit: h02: ('contig-100_1') You don't have to use ('..') to declare a string. Just 'your string' will do. You can use str.split to split your string by a character. (Not tested) string_on_left, numbers = 'contig-100_01'.split('-') left_number, right_number = numbers.split('_') left_number, right_number = int(left_number), int(right_number) Of course, you will want to replace the variable names. If you have more advanced parsing needs, you will want to look at regular expressions or blobs. -- http://mail.python.org/mailman/listinfo/python-list
Re: lstrip problem - beginner question
On 04/06/2013 16:21, mstagliamonte wrote: Hi everyone, I am a beginner in python and trying to find my way through... :) I am writing a script to get numbers from the headers of a text file. If the header is something like: h01 = ('scaffold_1') I just use: h01.lstrip('scaffold_') and this returns me '1' But, if the header is: h02: ('contig-100_0') if I use: h02.lstrip('contig-100_') this returns me with: '' ...basically nothing. What surprises me is that if I do in this other way: h02b = h02.lstrip('contig-100') I get h02b = ('_1') and subsequently: h02b.lstrip('_') returns me with: '1' which is what I wanted! Why is this happening? What am I missing? The methods 'lstrip', 'rstrip' and 'strip' don't strip a string, they strip characters. You should think of the argument as a set of characters to be removed. This code: h01.lstrip('scaffold_') will return the result of stripping the characters '', '_', 'a', 'c', 'd', 'f', 'l', 'o' and 's' from the left-hand end of h01. A simpler example: 'xyyxyabc'.lstrip('xy') 'abc' It strips the characters 'x' and 'y' from the string, not the string 'xy' as such. They are that way because they have been in Python for a long time, long before sets and such like were added to the language. -- http://mail.python.org/mailman/listinfo/python-list
Re: Source code as text/plain
On 04.06.2013 00:34, Carlos Nepomuceno wrote: Date: Mon, 3 Jun 2013 09:06:46 +1000 From: c...@zip.com.au To: c...@rebertia.com [...] http://hg.python.org/cpython/raw-file/tip/Lib/string.py What's the 'tip' tag? http://hg.python.org/cpython/help/tip Bye, Andreas -- http://mail.python.org/mailman/listinfo/python-list
Re: lstrip problem - beginner question
On Tuesday, June 4, 2013 11:41:43 AM UTC-4, Fábio Santos wrote: On 4 Jun 2013 16:34, mstagliamonte madm...@yahoo.it wrote: On Tuesday, June 4, 2013 11:21:53 AM UTC-4, mstagliamonte wrote: Hi everyone, I am a beginner in python and trying to find my way through... :) I am writing a script to get numbers from the headers of a text file. If the header is something like: h01 = ('scaffold_1') I just use: h01.lstrip('scaffold_') and this returns me '1' But, if the header is: h02: ('contig-100_0') if I use: h02.lstrip('contig-100_') this returns me with: '' ...basically nothing. What surprises me is that if I do in this other way: h02b = h02.lstrip('contig-100') I get h02b = ('_1') and subsequently: h02b.lstrip('_') returns me with: '1' which is what I wanted! Why is this happening? What am I missing? Thanks for your help and attention Max edit: h02: ('contig-100_1') You don't have to use ('..') to declare a string. Just 'your string' will do. You can use str.split to split your string by a character. (Not tested) string_on_left, numbers = 'contig-100_01'.split('-') left_number, right_number = numbers.split('_') left_number, right_number = int(left_number), int(right_number) Of course, you will want to replace the variable names. If you have more advanced parsing needs, you will want to look at regular expressions or blobs. Thanks, I will try it straight away. Still, I don't understand why the original command is returning me with nothing !? Have you got any idea? I am trying to understand a bit the 'nuts and bolts' of what I am doing and this result does not make any sense to me Regards Max -- http://mail.python.org/mailman/listinfo/python-list
Re: lstrip problem - beginner question
mstagliamonte wrote: Hi everyone, I am a beginner in python and trying to find my way through... :) I am writing a script to get numbers from the headers of a text file. If the header is something like: h01 = ('scaffold_1') I just use: h01.lstrip('scaffold_') and this returns me '1' But, if the header is: h02: ('contig-100_0') if I use: h02.lstrip('contig-100_') this returns me with: '' ...basically nothing. What surprises me is that if I do in this other way: h02b = h02.lstrip('contig-100') I get h02b = ('_1') and subsequently: h02b.lstrip('_') returns me with: '1' which is what I wanted! Why is this happening? What am I missing? abba.lstrip(ab) does not remove the prefix ab from the string abba. Instead it removes chars from the beginning until it encounters one that is not in ab. So t = s.lstrip(chars_to_be_removed) is roughly equivalent to t = s while len(t) 0 and t[0] in chars_to_be_removed: t = t[1:] If you want to remove a prefix use s = abba prefix = ab if s.startswith(prefix): s = s[len(prefix):] -- http://mail.python.org/mailman/listinfo/python-list
Re: lstrip problem - beginner question
On Tuesday, June 4, 2013 11:48:55 AM UTC-4, MRAB wrote: On 04/06/2013 16:21, mstagliamonte wrote: Hi everyone, I am a beginner in python and trying to find my way through... :) I am writing a script to get numbers from the headers of a text file. If the header is something like: h01 = ('scaffold_1') I just use: h01.lstrip('scaffold_') and this returns me '1' But, if the header is: h02: ('contig-100_0') if I use: h02.lstrip('contig-100_') this returns me with: '' ...basically nothing. What surprises me is that if I do in this other way: h02b = h02.lstrip('contig-100') I get h02b = ('_1') and subsequently: h02b.lstrip('_') returns me with: '1' which is what I wanted! Why is this happening? What am I missing? The methods 'lstrip', 'rstrip' and 'strip' don't strip a string, they strip characters. You should think of the argument as a set of characters to be removed. This code: h01.lstrip('scaffold_') will return the result of stripping the characters '', '_', 'a', 'c', 'd', 'f', 'l', 'o' and 's' from the left-hand end of h01. A simpler example: 'xyyxyabc'.lstrip('xy') 'abc' It strips the characters 'x' and 'y' from the string, not the string 'xy' as such. They are that way because they have been in Python for a long time, long before sets and such like were added to the language. Hey, Great! Now I understand! So, basically, it is also stripping the numbers after the '_' !! Thank you, I know a bit more now! Have a nice day everyone :) Max -- http://mail.python.org/mailman/listinfo/python-list
Re: Bools and explicitness [was Re: PyWart: The problem with print]
On Wed, Jun 5, 2013 at 1:44 AM, Rick Johnson rantingrickjohn...@gmail.com wrote: But we are really ignoring the elephant in the room. Implict conversion to Boolean is just a drop in the bucket compared to the constant shell game we are subjected to when reading source code. We so naively believe that a symbol named lst is a list object or a symbol age is a integer, when we could be totally wrong! This is the source of many subtle bugs!!! You know, if you want a language with strict type declarations and extreme run-time efficiency, there are some around. I think one of them might even be used to make the most popular Python. Give it a try, you might like it! There's NO WAY that you could accidentally pass a list to a function that's expecting a float, NO WAY to unexpectedly call a method on the wrong type of object. It would suit you perfectly! ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: lstrip problem - beginner question
In 1829efca-935d-4049-ba61-7138015a2...@googlegroups.com mstagliamonte madmax...@yahoo.it writes: Hi everyone, I am a beginner in python and trying to find my way through... :) I am writing a script to get numbers from the headers of a text file. If the header is something like: h01 = ('scaffold_1') I just use: h01.lstrip('scaffold_') and this returns me '1' But, if the header is: h02: ('contig-100_0') if I use: h02.lstrip('contig-100_') this returns me with: '' ...basically nothing. What surprises me is that if I do in this other way: h02b = h02.lstrip('contig-100') I get h02b = ('_1') and subsequently: h02b.lstrip('_') returns me with: '1' which is what I wanted! Why is this happening? What am I missing? It's happening because the argument you pass to lstrip() isn't an exact string to be removed; it's a set of individual characters, all of which will be stripped out. So, when you make this call: h02.lstrip('contig-100_') You're telling python to remove all of the characters in 'contig-100_' from the base string, which leaves nothing remaining. The reason it worked on your first example was that the character '1' didn't occur in your sample header string 'scaffold_'. If the underscore character is always the separating point in your headers, a better way might be to use the split() method instead of lstrip(). -- John Gordon A is for Amy, who fell down the stairs gor...@panix.com B is for Basil, assaulted by bears -- Edward Gorey, The Gashlycrumb Tinies -- http://mail.python.org/mailman/listinfo/python-list
Re: lstrip problem - beginner question
On 04/06/2013 16:49, mstagliamonte wrote: [strip the double line spaced nonsense] Can you please check your email settings. It's bad enough being plagued with double line spaced mail from google, having it come from yahoo is just adding insult to injury, thanks :) -- 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: lstrip problem - beginner question
Thanks to everyone! I didn't expect so many replies in such a short time! Regards, Max -- http://mail.python.org/mailman/listinfo/python-list
create new python file
Hi, Can anyone please tell me how to dynamically create a new python file within a program??? -- http://mail.python.org/mailman/listinfo/python-list
Re: Bools and explicitness [was Re: PyWart: The problem with print]
On 4 Jun 2013 17:04, Chris Angelico ros...@gmail.com wrote: On Wed, Jun 5, 2013 at 1:44 AM, Rick Johnson rantingrickjohn...@gmail.com wrote: But we are really ignoring the elephant in the room. Implict conversion to Boolean is just a drop in the bucket compared to the constant shell game we are subjected to when reading source code. We so naively believe that a symbol named lst is a list object or a symbol age is a integer, when we could be totally wrong! This is the source of many subtle bugs!!! You know, if you want a language with strict type declarations and extreme run-time efficiency, there are some around. I think one of them might even be used to make the most popular Python. Give it a try, you might like it! There's NO WAY that you could accidentally pass a list to a function that's expecting a float, NO WAY to unexpectedly call a method on the wrong type of object. It would suit you perfectly! I agree. I have never had this kind of issues in a dynamic language. Except when passing stuff to Django's fields. And in JavaScript. It seems like the thing was made to create references to `undefined`. And make them easily convertible to numbers and strings so that our calculations mysteriously fail when we're missing a function argument somewhere. -- http://mail.python.org/mailman/listinfo/python-list
Re: Bools and explicitness [was Re: PyWart: The problem with print]
On Jun 4, 10:44 am, Rick Johnson rantingrickjohn...@gmail.com wrote: What we need is a method by which we can validate a symbol and simultaneously do the vaidation in a manner that will cast light on the type that is expected. In order for this to work, you would need validators with unique type names if var.is_validList(): elif var.is_validString(): elif var.is_vaildTuple(): elif var.is_validInteger(): elif var.is_validFloat(): elif var.is_validDict(): etc... Actually, instead of forcing all types to have many specific methods, one builtin could solve the entire issue. The function would be similar to isinstance() taking two arguments object and type, however, it will not only guarantee type but also handle the conversion to Boolean: if is_valid(var, list): # if this block executes we know # the var is of type list and # var.length is greater than one. else: # if this block executes we know # that var is not of type list # or, var.length equals zero. The is_valid function would replace implicit Boolean conversion for all types in manner that is explicit enough whilst maintaining finger longevity. This is how you design a language for consistency and readability. Again. PUCKER UP WHO-VILLE! -- http://mail.python.org/mailman/listinfo/python-list
Re: create new python file
On 4 Jun 2013 17:14, kakararunachalserv...@gmail.com wrote: Hi, Can anyone please tell me how to dynamically create a new python file within a program??? That's generally a bad idea. Why are you doing that? That said, it's just like writing to a text file. So if you write python in a text file, you're good. -- http://mail.python.org/mailman/listinfo/python-list
Re: Bools and explicitness [was Re: PyWart: The problem with print]
On Jun 4, 11:00 am, Chris Angelico ros...@gmail.com wrote: You know, if you want a language with strict type declarations and extreme run-time efficiency, there are some around. I don't like declaring types everywhere, i hate it. I prefer duck typed languages, HOWEVER, in order for duck typing to work consistently you must have checks and balances that the programmer can apply when he feels necessary. My is_valid built in will bridge the gap. We won't be forced to declare types, but we should ALWAYS add type checks to our truth tests unless we want to create subtle bugs. is_valid IS the answer! -- http://mail.python.org/mailman/listinfo/python-list