Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-04 Thread Νικόλαος Κούρας
Τη Τετάρτη, 5 Ιουνίου 2013 9:03:41 π.μ. UTC+3, ο χρήστης Steven D'Aprano έγραψε:
Nikos wrote:
> > and the displayed filename after 'ls -l' returned was:
> > is -rw-r--r-- 1 nikos nikos 3511233 Jun 4 14:11 \305\365\367\336\
> > \364\357\365\ \311\347\363\357\375.mp3

> > There is no way at all to check the charset used to store it in hdd? It
> > should be UTF-8, but it doesn't look like it. Is there some linxu
> > command or some python command that will print out the actual encoding
> > of '\305\365\367\336\ \364\357\365\ \311\347\363\357\375.mp3' ?

> The Linux file system does not track encodings. It just stores bytes.
> There is no *reliable* way to guess the encoding that a bunch of bytes  
> came from. If your bytes look like 

> 0x48 0x65 0x6c 0x6c 0x6f 0x20 0x77 0x6f 0x72 0x6c 0x64 0x21

> (ASCII "Hello World!") then you might *guess* that the encoding is ASCII, 
> or UTF-8, or Latin-1. But in general, you can't go from the bytes to the 
> encoding. Encodings are out-of-band information.


Your explanation of encoding/decoding is excellent and iam storing this Steven!
So what i understand now is:

encoding = string -> (some charset used) -> charset bytes
decoding = bytes -> (have to know what charset has been used) -> original string

Have i understtod corrctly, that the *key* to the whole encode/decode process 
is the charset used/has to be used?

string = 'Ευχή του Ιησού.mp3'
abive string in unknown charset bytes = '\305\365\367\336\364\357\365\ 
\311\347\363\357\375.mp3'

We dont know they key(charset) used, but we do know the original form of the 
string, so it occured to me that if we write a python script to decode the 
mojabike bytestream to all available charsets then as some point the original 
string will appear back!


Won't you agree steven? Of course if that is likeley to work i don't know how 
to write it.


Hre is the comamnds you asked.
-
ni...@superhost.gr [~/www/data/apps]# printf %q\n\n *
100\ Mythoi\ tou\ 
Aiswpou.pdfnnAnekdotologio.exennBattleship.exenn$'\323\352\335  
  
\370\357\365 \335\355\341\355 \341\361\351\350\354\374.exe'nnKosmas\ o\ 
Aitwlos\
 -\ Profiteies.pdfnnLuxor\ 
Evolved.exennMonopoly.exenn$'\305\365\367\336 \364\35   
 7\365 
\311\347\363\357\375.mp3'nnOnline\ Movie\ Player.zipnnO\ Nomos\ tou\ Merfy  

  \ v1-2-3.zipnnOrthodoxo\ Imerologio.exennPac-Man.exennScrabble.exennTo\ 1o\ 
mou\
 vivlio\ gia\ to\ skaki.pdfnnVivlos\ gia\ Atheofovous.pdfnnV-Radio\ 
v2.4.msinnni

ni...@superhost.gr [~/www/data/apps]# ls -b *
100\ Mythoi\ tou\ Aiswpou.pdf*
Online\ Movie\ Player.zip*
Anekdotologio.exe*O\ 
Nomos\ tou\ Merfy\ v1-2-3.zip
Battleship.exe
Orthodoxo\ Imerologio.exe*
\323\352\335\370\357\365\ \335\355\341\355\ \341\361\351\350\354\374.exe  
Pac-Man.exe
Kosmas\ o\ Aitwlos\ -\ Profiteies.pdf*
Scrabble.exe
Luxor\ Evolved.exeTo\ 
1o\ mou\ vivlio\ gia\ to\ skaki.pdf*
Monopoly.exe  
Vivlos\ gia\ Atheofovous.pdf*
\305\365\367\336\ \364\357\365\ \311\347\363\357\375.mp3  
V-Radio\ v2.4.msi
ni...@superhost.gr [~/www/data/apps]#
---

I uploaded via FileZilla the files with english chars and then reanmes from 
CentOS, i did that to avoid renaming them from within my Win8. I though it was 
betetr to rename form within linux itself.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Bools and explicitness [was Re: PyWart: The problem with "print"]

2013-06-04 Thread Russ P.
On Tuesday, June 4, 2013 8:44:11 AM UTC-7, Rick Johnson wrote:

> Yes, but the problem is not "my approach", rather the lack
> 
> of proper language design (my apologizes to the "anointed
> 
> one". ;-)

If you don't like implicit conversion to Boolean, then maybe you should be 
using another language -- and I mean that in a constructive sense. I'm not 
particularly fond of it either, but I switched from Python to another language 
a while back. The issue is not a lack of "proper language design" but rather a 
language design philosophy that values conciseness and simplicity over 
explicitness and rigor. 

Implicit conversion to Boolean is only one of many language features that are 
questionable for critical production software. Another is the convention of 
interpreting negative indices as counting backward from the end of a list or 
sequence. Yeah, I thought that was elegant... until it bit me. Is it a bad 
idea? Not necessarily. It certainly enhances programmer productivity, and it 
can be done correctly "almost" all the time. But that one time in a hundred or 
a thousand when you accidentally use a negative index can be a bitch.

But then, what would you expect of a language that allows you to write

x = 1
x = "Hello"

It's all loosey goosey -- which is fine for many applications but certainly not 
for critical ones.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-04 Thread Steven D'Aprano
On Tue, 04 Jun 2013 08:47:01 +, Steven D'Aprano wrote:

> Please run these commands, and show what result they give:
> 
> alias ls
> 
> printf %q\\n *.mp3
> 
> ls -b *.mp3


Do you have an answer for this yet? Better still, change the last two 
commands to this:


printf %q\\n *

ls -b *


> 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


Of course that second command is wrong, it needs quotes:

mv 1.mp3 "Eυχή του Ιησού.mp3"



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-04 Thread Νικόλαος Κούρας
Τη Τετάρτη, 5 Ιουνίου 2013 8:40:39 π.μ. UTC+3, ο χρήστης Michael Torrie έγραψε:
> On 06/04/2013 10:15 PM, Νικόλαος Κούρας wrote:
> 
> > One of my Greek filenames is "Ευχή του Ιησού.mp3". Just a Greek
> 
> > filename with spaces. Is there a problem when a filename contain both
> 
> > english and greek letters? Isn't it still a unicode string?
> 
> > 
> 
> > All i did in my CentOS was 'mv "Euxi tou Ihsou.mp3" "Ευχή του
> 
> > Ιησού.mp3"
> 
> > 
> 
> > and the displayed filename after 'ls -l' returned was:
> 
> > 
> 
> > is -rw-r--r-- 1 nikos nikos 3511233 Jun 4 14:11 \305\365\367\336\
> 
> > \364\357\365\ \311\347\363\357\375.mp3
> 
> > 
> 
> > There is no way at all to check the charset used to store it in hdd? 
> 
> > It should be UTF-8, but it doesn't look like it. Is there some linxu
> 
> > command or some python command that will print out the actual
> 
> > encoding of '\305\365\367\336\ \364\357\365\
> 
> > \311\347\363\357\375.mp3' ?
> 
> 
> 
> I can see that you are starting to understand things. I can't answer
> your question (don't know the answer), but you're correct about one
> thing.  A filename is just a sequence of bytes.  We'd hope it would be
> utf-8, but it could be anything.  Even worse, it's not possible to tell
> from a byte stream what encoding it is unless we just try one and see
> what happens.  Text editors, for example, have to either make a guess
> (utf-8 is a good one these days), or ask, or try to read from the first
> line of the file using ascii and see if there's a source code character 
> set command to give it an idea.


Um, is there a way even if we don't actually know the encoding CentOS used to 
store the filename to hdd to tell Python to just open the bytestream as it is?

I don't know if its possible, but iam looking for a way to skip the encoding, 
since we have now way of knowing what this is.

This is very weird because:


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 [~]#

all i did it was a simple rename from english to greek. Since locale is set to 
use utf8, shouldnt the result in the hdd be an utf-8 bytestream?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-04 Thread Steven D'Aprano
On Tue, 04 Jun 2013 21:15:23 -0700, Νικόλαος Κούρας wrote:

> One of my Greek filenames is "Ευχή του Ιησού.mp3". Just a Greek filename
> with spaces.
> Is there a problem when a filename contain both english and greek
> letters? Isn't it still a unicode string?

No problem, and Unicode includes both English and Greek letters.


> All i did in my CentOS was 'mv "Euxi tou Ihsou.mp3" "Ευχή του Ιησού.mp3"

That's not what you wrote earlier. You said you used FileZilla to 
transfer the files from Windows 8.


> and the displayed filename after 'ls -l' returned was:
> 
> is -rw-r--r-- 1 nikos nikos 3511233 Jun 4 14:11 \305\365\367\336\
> \364\357\365\ \311\347\363\357\375.mp3
> 
> There is no way at all to check the charset used to store it in hdd? It
> should be UTF-8, but it doesn't look like it. Is there some linxu
> command or some python command that will print out the actual encoding
> of '\305\365\367\336\ \364\357\365\ \311\347\363\357\375.mp3' ?

You have misunderstood.

The Linux file system does not track encodings. It just stores bytes.

There is no *reliable* way to guess the encoding that a bunch of bytes 
came from. If your bytes look like 

0x48 0x65 0x6c 0x6c 0x6f 0x20 0x77 0x6f 0x72 0x6c 0x64 0x21

(ASCII "Hello World!") then you might *guess* that the encoding is ASCII, 
or UTF-8, or Latin-1. But in general, you can't go from the bytes to the 
encoding. Encodings are out-of-band information.


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Apache and suexec issue that wont let me run my python script

2013-06-04 Thread Νικόλαος Κούρας
Τη Τετάρτη, 5 Ιουνίου 2013 8:23:12 π.μ. UTC+3, ο χρήστης alex23 έγραψε:
> On Jun 5, 3:11 pm, Νικόλαος Κούρας  wrote:
> 
> > I'm not trolling, you are the one that do not understand.
> 
> >
> 
> > Here i swicthed the code from:
> 
> > path = "/home/nikos/www/data/apps/"
> 
> >
> 
> > to this since '/home/nikos/public_html/cgi-bin' = '/home/nikos/www/cgi-bin' 
> > as i said:
> 
> >
> 
> > # Compute a set of current fullpaths
> 
> > path = "/home/nikos/public_html/data/apps/"
> 
> >
> 
> > Same error.
> 
> 
> 
> "/home/nikos/public_html/data/apps/" <> "/home/nikos/public_html/cgi-
> 
> bin/"
> 
> 
> 
> Are you even reading the error messages?

What do you mean? Yes i have read the error messsage and i can't understand wht 
file it can't find.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-04 Thread Steven D'Aprano
On Tue, 04 Jun 2013 10:23:33 -0700, Νικόλαος Κούρας wrote:

> What on eart is this damn error: Michael tried to explain to me about
> surrogates but dont think i understand it.
> 
> Encoding giving me trouble years now.
> 
> [Tue Jun 04 20:19:53 2013] [error] [client 46.12.95.59] Original
> exception was: [Tue Jun 04 20:19:53 2013] [error] [client 46.12.95.59]
> Traceback (most recent call last): [Tue Jun 04 20:19:53 2013] [error]
> [client 46.12.95.59]   File "files.py", line 72, in  [Tue Jun 04
> 20:19:53 2013] [error] [client 46.12.95.59] cur.execute('''SELECT
> url FROM files WHERE url = %s''', (fullpath,) ) [Tue Jun 04 20:19:53
> 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 20:19:53 2013] [error] [client
> 46.12.95.59] query = query.encode(charset) [Tue Jun 04 20:19:53
> 2013] [error] [client 46.12.95.59] UnicodeEncodeError: 'utf-8' codec
> can't encode character '\\udcd3' in position 61: surrogates not allowed
> 
> 
> 
> PLEASE TELL EM WHAT TO TRY, PLEASE FOR THE LOVE OF GOD, IAM SO
> FRUSTRATED NOT BEING ABLE TO DEAL WITH THIS.

Calm down. I know it is frustrating.

On a Linux system, the file system stores bytes, and only bytes. The file 
system does no validation of the bytes you give, except to check that 
there are no 0x00 and 0x2f bytes (ASCII '\0' and '/') in the file name. 
That's all.

So, if one program thinks that it should be sending file names in, say, 
UTF-16 or or ISO-8859-7 encoding, it will take a string like "Νικόλαος" 
and the file system will see bytes like these:

py> s = 'Νικόλαος'
py> s.encode('UTF-16be')
b'\x03\x9d\x03\xb9\x03\xba\x03\xcc\x03\xbb\x03\xb1\x03\xbf\x03\xc2'

py> s.encode('iso-8859-7')
b'\xcd\xe9\xea\xfc\xeb\xe1\xef\xf2'


Notice that the same string gives you completely different bytes. And 
likewise, the same bytes will give you different strings, depending on 
the encoding you use.


Now, if you try to read the file name using a program that expects UTF-8, 
it will either see some sort of mojibake garbage characters, or get some 
sort of error:

py> s.encode('UTF-16be').decode('utf-8')
Traceback (most recent call last):
  File "", line 1, in 
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x9d in position 1: 
invalid start byte

py> s.encode('iso-8859-7').decode('utf-8')
Traceback (most recent call last):
  File "", line 1, in 
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcd in position 0: 
invalid continuation byte


Somehow, I don't know how because I didn't see it happen, you have one or 
more files in that directory where the file name as bytes is invalid when 
decoded as UTF-8, but your system is set to use UTF-8. So to fix this you 
need to rename the file using some tool that doesn't care quite so much 
about encodings. Use the bash command line to rename each file in turn 
until the problem goes away.



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-04 Thread Michael Torrie
On 06/04/2013 10:15 PM, Νικόλαος Κούρας wrote:
> One of my Greek filenames is "Ευχή του Ιησού.mp3". Just a Greek
> filename with spaces. Is there a problem when a filename contain both
> english and greek letters? Isn't it still a unicode string?
> 
> All i did in my CentOS was 'mv "Euxi tou Ihsou.mp3" "Ευχή του
> Ιησού.mp3"
> 
> and the displayed filename after 'ls -l' returned was:
> 
> is -rw-r--r-- 1 nikos nikos 3511233 Jun 4 14:11 \305\365\367\336\
> \364\357\365\ \311\347\363\357\375.mp3
> 
> There is no way at all to check the charset used to store it in hdd? 
> It should be UTF-8, but it doesn't look like it. Is there some linxu
> command or some python command that will print out the actual
> encoding of '\305\365\367\336\ \364\357\365\
> \311\347\363\357\375.mp3' ?

I can see that you are starting to understand things. I can't answer
your question (don't know the answer), but you're correct about one
thing.  A filename is just a sequence of bytes.  We'd hope it would be
utf-8, but it could be anything.  Even worse, it's not possible to tell
from a byte stream what encoding it is unless we just try one and see
what happens.  Text editors, for example, have to either make a guess
(utf-8 is a good one these days), or ask, or try to read from the first
line of the file using ascii and see if there's a source code character
set command to give it an idea.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Bools and explicitness [was Re: PyWart: The problem with "print"]

2013-06-04 Thread alex23
On Jun 5, 3:28 pm, Steven D'Aprano  wrote:
> How many years has Rick been coming here, proclaiming loudly  [a]nd yet, 
> he still has no clue what
>  actually means.

It's not just duck typing.


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Bools and explicitness [was Re: PyWart: The problem with "print"]

2013-06-04 Thread Steven D'Aprano
On Wed, 05 Jun 2013 02:27:26 +1000, Chris Angelico wrote:

> On Wed, Jun 5, 2013 at 2:19 AM, Rick Johnson
>  wrote:
>> On Jun 4, 11:00 am, Chris Angelico  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!
> 
> Option 1:
> 
> void C_function(int x)
> 
> Option 2:
> 
> def Python_function(x):
> assert isinstance(x,int)
> 
> Is there a fundamental difference? You're basically proposing Option 2
> while detesting Option 1.


How many years has Rick been coming here, proclaiming loudly how much he 
loves Python's duck-typing? Ten years? And yet, he still has no clue what 
it actually means.

If you're performing a type-check, IT ISN'T DUCK-TYPING.

Duck typing means you don't care whether you have an int, so long as 
whatever object you get is usable where an int is usable. 

Now, there are many places in my own code where I decide that I wish to 
prohibit duck-typing. "Here I insist on an actual int, not just any old 
number." There are, sometimes, good reasons for this. But every time I do 
this, I am *not* duck-typing, I am doing a runtime type check which is 
completely opposite in intent to duck-typing. (There's no short name for 
this -- it's not quite static typing, because it happens at runtime and 
isn't enforced by the language.) 

It's almost like Rick declares that he's a great supporter of the free 
market, and that everyone should be free to buy and trade in whatever 
property they wish, while insisting that nothing can be bought or sold 
without permission from the government first.



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Bools and explicitness [was Re: PyWart: The problem with "print"]

2013-06-04 Thread Michael Torrie
On 06/04/2013 05:21 PM, Rick Johnson wrote:
> If you still feel that this idea is garbage, then, keep on writing
> your sloppy code. My proposal is the best method to handle the
> problems that arise with duck typed languages in a manner that is not
> restrictive or laborious -- it's actually quite elegant.

Like most of your proposals, this does not have anything to do with the
python syntax itself.  You just demonstrated code that does what you
want.  So use it then.  Adopt it in your own code, encourage others to
use it.  No changes to Python are needed.  If this technique proves its
value, then it will be adopted.  If not, it will die.  Start using it in
one of your major open source projects.

> *school-bell-rings*

It's one thing to patronize people as you try to do to D'Aprano (and yes
I admit that most replies to your posts are often patronizing to you in
return), but you do realize this infantile attempt to try to make
yourself look smarter than others really reflects poorly on you?  I for
one feel badly for you on this count, or at least embarrassed.  So just
a suggestion... drop the school bell and teacher stuff (or at least
share your qualifications with us).  It's really tiring, though to be
fair not quite as tiring as trying to help someone with an iron skull
get a CGI script working.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Apache and suexec issue that wont let me run my python script

2013-06-04 Thread alex23
On Jun 5, 3:11 pm, Νικόλαος Κούρας  wrote:
> I'm not trolling, you are the one that do not understand.
>
> Here i swicthed the code from:
> path = "/home/nikos/www/data/apps/"
>
> to this since '/home/nikos/public_html/cgi-bin' = '/home/nikos/www/cgi-bin' 
> as i said:
>
> # Compute a set of current fullpaths
> path = "/home/nikos/public_html/data/apps/"
>
> Same error.

"/home/nikos/public_html/data/apps/" <> "/home/nikos/public_html/cgi-
bin/"

Are you even reading the error messages?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to get an integer from a sequence of bytes

2013-06-04 Thread Tim Roberts
Grant Edwards  wrote:

>On 2013-06-03, Dan Stromberg  wrote:
>>
>> 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.

A single machine word was 60 bits, so a single register read got you 10
characters.  There were three sets of registers -- the X registers were 60
bits, the A and B registers were 18 bits, which was the size of the largest
possible address.

CDC didn't actually use the term "byte".  That was IBM's domain.

When ASCII became unavoidable, most programs changed to using 5x 12-bit
"bytes" per word.

Ah, memories.  I spent 10 years working for Control Data.
-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Apache and suexec issue that wont let me run my python script

2013-06-04 Thread Νικόλαος Κούρας
Τη Τετάρτη, 5 Ιουνίου 2013 7:59:31 π.μ. UTC+3, ο χρήστης alex23 έγραψε:
> On Jun 5, 2:40 pm, Νικόλαος Κούρας  wrote:
> 
> > Of course '/home/nikos/public_html/cgi-bin' = '/home/nikos/www/cgi-bin'
> 
> > What this has to do with what i asked?
> 
> 
> 
> You display an error of "No such file or directory" and you wonder why 
> I'm trying to confirm the two locations are the same.
> 

> Can you finally admit you're trolling now?

I'm not trolling, you are the one that do not understand.

Here i swicthed the code from:

# 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) )

to this since '/home/nikos/public_html/cgi-bin' = '/home/nikos/www/cgi-bin' as 
i said:

# Compute a set of current fullpaths
fullpaths = set()
path = "/home/nikos/public_html/data/apps/"

for root, dirs, files in os.walk(path):
for fullpath in files:
fullpaths.add( os.path.join(root, fullpath) )


--
ni...@superhost.gr [~/www/cgi-bin]# [Wed Jun 05 08:09:14 2013] [error] [client 
46.12.95.59] (2)No such file or directory: exec of 
'/home/nikos/public_html/cgi-bin/koukos.py' failed
[Wed Jun 05 08:09:14 2013] [error] [client 46.12.95.59] Premature end of script 
headers: koukos.py
[Wed Jun 05 08:09:14 2013] [error] [client 46.12.95.59] File does not exist: 
/home/nikos/public_html/500.shtml

Same error.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-04 Thread Νικόλαος Κούρας
Τη Τετάρτη, 5 Ιουνίου 2013 7:47:40 π.μ. UTC+3, ο χρήστης alex23 έγραψε:
> On Jun 5, 1:28 pm, Νικόλαος Κούρας  wrote:
> 
> > AS you have seen i've been struggling days now to get a solution to this 
> > and the closing parenthesis is not the prbpoem here, unicode.
> 
> 
> 
> Oh really?
> 
> 
> 
> > if they are unicode then i really see no trouble when trying to:
> 
> > cur.execute('''SELECT url FROM files WHERE url = %s''', ( fullpath, )
> 
> > but [t]his is what i'm still getting:
> 
> > [Tue Jun 04 19:50:16 2013] [error] [client 46.12.95.59] data = 
> > cur.fetchone()#URL is unique, so should only be one
> 
> > [Tue Jun 04 19:50:16 2013] [error] [client 46.12.95.59]^
> 
> > [Tue Jun 04 19:50:16 2013] [error] [client 46.12.95.59] SyntaxError: 
> > invalid syntax
> 
> 
> 
> Unicode is not producing the SyntaxError you're seeing here.
> 
> 
> 
> > YOU of all people should not speak at all, because you haven't helped me a 
> > bit.
> 
> 
> 
> Yeah, advising you _not_ to do this crap on a production machine was
> 
> clearly lost on you. That's not my failing, though, it's your's.
> 
> 
> 
> > Its funny, how knowledge people that in facte tried to help me treat me 
> > with respect while people like you who have never been of any help tend to 
> > just bitch all the way along.
> 
> 
> 
> 1) For many of us, this is our _profession_ and you're asking us to
> 
> provide you with _free_ support while doing SFA to resolve your
> 
> inadequate understanding.
> 
> 2) If it names itself after a troll, and it trolls like a troll,
> 
> there's a pretty good chance it's a troll.
> 
> 3) Your whining and begging is treating _us_ with no respect, so I
> 
> guess we're all even.
> 
> 
> 
> Your whole approach is one of cargo cult programming and it's tedious.
> 
> Sysadmin, educate thyself!

Keep bithching professional pythoneer, you are doing great. 
I'm too tired to even reply to your rumblings.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyWart: The problem with "print"

2013-06-04 Thread Steven D'Aprano
On Tue, 04 Jun 2013 05:23:19 -0700, jmfauth wrote:

> How is is possible to arrive to such a situation ? The answer if far
> beyond my understanding

Truer words have never been spoken.


> (although I have my opinion on the subject).


http://en.wikipedia.org/wiki/Dunning–Kruger_effect



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Apache and suexec issue that wont let me run my python script

2013-06-04 Thread alex23
On Jun 5, 2:40 pm, Νικόλαος Κούρας  wrote:
> Of course '/home/nikos/public_html/cgi-bin' = '/home/nikos/www/cgi-bin'
> What this has to do with what i asked?

You display an error of "No such file or directory" and you wonder why
I'm trying to confirm the two locations are the same.

Can you finally admit you're trolling now?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lstrip problem - beginner question

2013-06-04 Thread Larry Hudson

On 06/04/2013 08:21 AM, 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



The lstrip() function is the wrong one to use here.  The command 
help(str.lstrip) gives:

lstrip(...)
S.lstrip([chars]) -> str

Return a copy of the string S with leading whitespace removed.
If chars is given and not None, remove characters in chars instead.

IOW, it does NOT strip the given string, but all the characters in the given 
string.
So in your second example it (correctly) removes everything and gives you an empty string as the 
result.


One possible alternative is to use slicing:

h02 = '>contig-100_0'
h03 = '>contig-100_'
result = h02[len(h03):]

Or some similar variation, possibly adding a startswith() function for some simple error 
checking.  Of course, other approaches are possible as well,


 -=- Larry -=-

--
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-04 Thread alex23
On Jun 5, 1:28 pm, Νικόλαος Κούρας  wrote:
> AS you have seen i've been struggling days now to get a solution to this and 
> the closing parenthesis is not the prbpoem here, unicode.

Oh really?

> if they are unicode then i really see no trouble when trying to:
> cur.execute('''SELECT url FROM files WHERE url = %s''', ( fullpath, )
> but [t]his is what i'm still getting:
> [Tue Jun 04 19:50:16 2013] [error] [client 46.12.95.59] data = 
> cur.fetchone()#URL is unique, so should only be one
> [Tue Jun 04 19:50:16 2013] [error] [client 46.12.95.59]^
> [Tue Jun 04 19:50:16 2013] [error] [client 46.12.95.59] SyntaxError: invalid 
> syntax

Unicode is not producing the SyntaxError you're seeing here.

> YOU of all people should not speak at all, because you haven't helped me a 
> bit.

Yeah, advising you _not_ to do this crap on a production machine was
clearly lost on you. That's not my failing, though, it's your's.

> Its funny, how knowledge people that in facte tried to help me treat me with 
> respect while people like you who have never been of any help tend to just 
> bitch all the way along.

1) For many of us, this is our _profession_ and you're asking us to
provide you with _free_ support while doing SFA to resolve your
inadequate understanding.
2) If it names itself after a troll, and it trolls like a troll,
there's a pretty good chance it's a troll.
3) Your whining and begging is treating _us_ with no respect, so I
guess we're all even.

Your whole approach is one of cargo cult programming and it's tedious.
Sysadmin, educate thyself!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Apache and suexec issue that wont let me run my python script

2013-06-04 Thread Νικόλαος Κούρας
Τη Τετάρτη, 5 Ιουνίου 2013 7:34:55 π.μ. UTC+3, ο χρήστης alex23 έγραψε:
> On Jun 5, 1:55 pm, Νικόλαος Κούρας  wrote:
> 
> > [Wed Jun 05 06:49:56 2013] [error] [client 46.12.95.59] (2)No such file or 
> > directory: exec of '/home/nikos/public_html/cgi-bin/koukos.py' failed
> 
> 
> 
> > The script though its interpretign  correctly as seen from
> 
> > ni...@superhost.gr [~/www/cgi-bin]# python koukos.py
> 
> 
> 
> Unless you're symlinking and expect us to use our psychic powers to
> 
> work that out, '/home/nikos/public_html/cgi-bin/koukos.py' <> '~/www/
> 
> cgi-bin/koukos.py'.

Of course '/home/nikos/public_html/cgi-bin' = '/home/nikos/www/cgi-bin'
What this has to do with what i asked?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Apache and suexec issue that wont let me run my python script

2013-06-04 Thread Νικόλαος Κούρας
Here is the script:


#!/usr/bin/python
# coding=utf-8

import cgitb; cgitb.enable()
import cgi, os, sys, locale, codecs
from http import cookies

#needed line, script does *not* work without it
sys.stdout = codecs.getwriter('utf-8')(sys.stdout.detach())

# initialize cookie
cookie = cookies.SimpleCookie( os.environ.get('HTTP_COOKIE') )
cookie.load( cookie )
nikos = cookie.get('nikos')

# if visitor cookie does exist
if nikos:
message = "ΑΠΟ ΤΗΝ ΕΠΟΜΕΝΗ ΕΠΙΣΚΕΨΗ ΣΟΥ ΘΑ ΣΕ ΥΠΟΛΟΓΙΖΩ ΩΣ ΕΠΙΣΚΕΠΤΗ 
ΑΥΞΑΝΟΝΤΑΣ ΤΟΝ ΜΕΤΡΗΤΗ!"
cookie['nikos'] = 'admin'
cookie['nikos']['path'] = '/'
cookie['nikos']['expires'] = -1 #this cookie will expire now
else:
message  = "ΑΠΟ ΔΩ ΚΑΙ ΣΤΟ ΕΞΗΣ ΔΕΝ ΣΕ ΕΙΔΑ, ΔΕΝ ΣΕ ΞΕΡΩ, ΔΕΝ ΣΕ 
ΑΚΟΥΣΑ! ΘΑ ΕΙΣΑΙ ΠΛΕΟΝ Ο ΑΟΡΑΤΟΣ ΕΠΙΣΚΕΠΤΗΣ!!"
cookie['nikos'] = 'admin'
cookie['nikos']['path'] = '/'
cookie['nikos']['expires'] = 60*60*24*30*12 #this cookie 
will expire in a year


print( cookie, "Content-type: text/html; charset=utf-8\n", message )

sys.exit(0)
===

This doesn't make sense to me at all.I'll iam tryign to set is a cookie, iwas 
so happy finally disablin bloody 'suexec' and now this.

[Wed Jun 05 06:49:56 2013] [error] [client 46.12.95.59] (2)No such file or 
directory: exec of '/home/nikos/public_html/cgi-bin/koukos.py' failed 
[Wed Jun 05 06:49:56 2013] [error] [client 46.12.95.59] Premature end of script 
headers: koukos.py
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Apache and suexec issue that wont let me run my python script

2013-06-04 Thread alex23
On Jun 5, 1:55 pm, Νικόλαος Κούρας  wrote:
> [Wed Jun 05 06:49:56 2013] [error] [client 46.12.95.59] (2)No such file or 
> directory: exec of '/home/nikos/public_html/cgi-bin/koukos.py' failed

> The script though its interpretign  correctly as seen from
> ni...@superhost.gr [~/www/cgi-bin]# python koukos.py

Unless you're symlinking and expect us to use our psychic powers to
work that out, '/home/nikos/public_html/cgi-bin/koukos.py' <> '~/www/
cgi-bin/koukos.py'.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-04 Thread Νικόλαος Κούρας
One of my Greek filenames is "Ευχή του Ιησού.mp3". 
Just a Greek filename with spaces. 
Is there a problem when a filename contain both english and greek letters? 
Isn't it still a unicode string? 

All i did in my CentOS was 'mv "Euxi tou Ihsou.mp3" "Ευχή του Ιησού.mp3" 

and the displayed filename after 'ls -l' returned was:

is -rw-r--r-- 1 nikos nikos 3511233 Jun 4 14:11 \305\365\367\336\ \364\357\365\ 
\311\347\363\357\375.mp3

There is no way at all to check the charset used to store it in hdd?
It should be UTF-8, but it doesn't look like it.
Is there some linxu command or some python command that will print out the 
actual encoding of '\305\365\367\336\ \364\357\365\ \311\347\363\357\375.mp3' ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Issue values dictionary

2013-06-04 Thread claire morandin
@alex23 I can't thank you enough this really helped me so much, not only fixing 
my issue but also understanding where was my original error

Thanks a lot

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-04 Thread Νικόλαος Κούρας
Τη Τετάρτη, 5 Ιουνίου 2013 6:44:38 π.μ. UTC+3, ο χρήστης Νικόλαος Κούρας έγραψε:
> Τη Τετάρτη, 5 Ιουνίου 2013 12:47:17 π.μ. UTC+3, ο χρήστης Chris Angelico 
> έγραψε:
> 
> 
> 
> > >This indicates that i'am reading the filenames in a different encoding 
> > >than > > >what they actually are? What is i try to use bytes for path 
> > >specifications,  > > >have Python decode them in 'utf-8' ?
> 

> > > fullpaths.add( os.path.join(root, fullpath).encode('utf-8') )

> > For some reason you have an invalid Unicode codepoint in your string. Fix 
> > that. 

> Can you be more clear please?
> my string is "Ευχή του Ιησού.mp3". Just a Greek filename with spaces. 
> Is there a problem when a filename contain both english and greek letters?
> Isn't it still a unicode stream?


I can't actually check what the actual encoding of a filename stored in hdd is. 
It should be UTF-8, but it is not. It's probably whatever encoding i had on 
Windows. Perhaps making sure "root" and "fullpath" are bytes. Then the returned 
filenames should be bytes as well?

Is this achievable by doing?
print( root.decode('utf-8'), fullpath.decode('utf-8') )
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Apache and suexec issue that wont let me run my python script

2013-06-04 Thread Νικόλαος Κούρας
Τη Τετάρτη, 5 Ιουνίου 2013 1:12:26 π.μ. UTC+3, ο χρήστης Chris Angelico έγραψε:
> On Wed, Jun 5, 2013 at 3:12 AM, Νικόλαος Κούρας  wrote:
> 
> > I know what full root access mean.
> 
> > I also trust you.
> 
> > I'm hopeless man, its 1 week now dealing with this.
> 
> 
> 
> The call is strong... I could rule the galaxy alongside my father...
> 
> I've searched my feelings, and I know this to be true!
> 
> 
> 
> Okay. I accept. I'll do as I promised. Might be interesting, and
> 
> educative - for someone, at least.

Good Day Chris, thanks for accepting.

Please mail me and i will send you the root login credentials.
Before that happens i want to tell you that i have manages to disable 'suexec' 
and the error now became:


[Wed Jun 05 06:49:56 2013] [error] [client 46.12.95.59] (2)No such file or 
directory: exec of '/home/nikos/public_html/cgi-bin/koukos.py' failed
[Wed Jun 05 06:49:56 2013] [error] [client 46.12.95.59] Premature end of script 
headers: koukos.py

The script though its interpretign  correctly as seen from

ni...@superhost.gr [~/www/cgi-bin]# python koukos.py
Set-Cookie: nikos=admin; expires=Sat, 31 May 2014 03:55:16 GMT; Path=/ 
Content-type: text/html; charset=utf-8
 ΞΞ Ξ ΞΞ© ΞΞΞ Ξ£Ξ�Ξ £ ΞΞΞ
 ni...@superhost.gr [~/www/cgi-bin]#

The mojabike is Greek as terminal outputs it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-04 Thread Νικόλαος Κούρας
Τη Τετάρτη, 5 Ιουνίου 2013 12:47:17 π.μ. UTC+3, ο χρήστης Chris Angelico έγραψε:

> >This indicates that i'am reading the filenames in a different encoding than 
> >> > >what they actually are? What is i try to use bytes for path 
> >specifications,  > > >have Python decode them in 'utf-8' ?

> > fullpaths.add( os.path.join(root, fullpath).encode('utf-8') )

> For some reason you have an invalid Unicode codepoint in your string. Fix 
> that.

Can you be more clear please?
my string is "Ευχή του Ιησού.mp3". Just a Greek filename with spaces.
Is there a problem when a filename contain both english and greek letters?
Isn't it still a unicode stream?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to increment date by week?

2013-06-04 Thread steve . ferg . bitbucket
pyfdate -- http://www.ferg.org/pyfdate/

from pyfdate import Time 
w = Time(2013,1,2) # start with January 2, 2013, just for example

# print the ISO weeknumber and date for 52 weeks
# date looks like this: October 31, 2005
for i in range(52):
w = w.plus(weeks=1)
print (w.weeknumber, w.d)


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-04 Thread Νικόλαος Κούρας
Τη Τρίτη, 4 Ιουνίου 2013 10:31:20 μ.μ. UTC+3, ο χρήστης Lele Gaifax έγραψε:

> The code above was my (failed) attempt to focus your attention on why
> one of your scripts raised a SyntaxError: translating that code in plain 
> english, that line (the "stmt" variable above) contains *two* open
> brackets, and *one* close bracket.

Lele, iam sorry fot that these days i do nothing, all day long but try to solve 
2 issues, one of it being fils.py which this encoding issues. i missed the 
parentheses because i was tired. Just added it.

I believe that in order to be able to solve this i have to

a) Find out the actual encoding of my greek filenames are into, after the 
rename took place from english to greek chars at the CentOS. How can i check 
that

b) Findind out (a) will help tell python to decode 'fullpath' from the weird 
unknown yet to be discovered encoded bytestream to 'utf-8' like:

cur.execute('''SELECT url FROM files WHERE url = %s''', 
(fullpath.decode('weird_bytestream') ) )

Is this the right aproach? I went to sleep yesterday and my mind was still 
bothered with this encoding problem i'm dealing with.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-04 Thread Chris Angelico
On Wed, Jun 5, 2013 at 1:28 PM, Νικόλαος Κούρας  wrote:
>
> YOU of all people should not speak at all, because you haven't helped me a 
> bit.
> Its funny, how knowledge people that in facte tried to help me treat me with 
> respect while people like you who have never been of any help tend to just 
> bitch all the way along.


You sure don't know respect when you don't see it.

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-04 Thread Νικόλαος Κούρας
Τη Τετάρτη, 5 Ιουνίου 2013 4:28:17 π.μ. UTC+3, ο χρήστης alex23 έγραψε:
> On Jun 5, 5:32 am, Νικόλαος Κούρας  wrote:
> 
> > Lele the output of:
> 
> >
> 
> > stmt = "cur.execute('''SELECT url FROM files WHERE url = %s''', ( fullpath, 
> > )"
> 
> > chars_count = Counter(stmt)
> 
> > print("Number of '(': %d" % chars_count['('])
> 
> > print("Number of ')': %d" % chars_count[')'])
> 
> >
> 
> > is:
> 
> >
> 
> > Number of '(': 2 Number of ')': 1
> 
> >
> 
> > What do you make out of this please?
> 
> 
> 
> Just a reminder to everyone that the OP originally went by the name of
> 
> Ferrous Cranus:
> 
> http://redwing.hutman.net/~mreed/warriorshtm/ferouscranus.htm
> 
> 
> 
> He's told there's a missing parenthesis, he dismisses the claim. He's
> 
> given code that demonstrates the missing parenthesis, and he acts
> 
> confused. The list is rapidly becoming his support group for _his
> 
> business_, and the bulk of it has very little to do with Python
> 
> itself.
> 
> 
> 
> I've been struggling for a month to get an inheritance chain working
> 
> with fresnel lenses, should I be posting every single bug I hit here
> 
> every 10 minutes then bump them 10 minutes later when no one responds?
> 
> Is that what the list is for now? We don't do people's home work for
> 
> them, so why are we doing his _work_ for him?

AS you have seen i've been struggling days now to get a solution to this and 
the closing parenthesis is not the prbpoem here, unicode.

YOU of all people should not speak at all, because you haven't helped me a bit.
Its funny, how knowledge people that in facte tried to help me treat me with 
respect while people like you who have never been of any help tend to just 
bitch all the way along.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Issue values dictionary

2013-06-04 Thread alex23
On Jun 5, 12:41 pm, claire morandin  wrote:
> But I have a problem storing all size length to the value size as it is 
> always comes back with the last entry.
> Could anyone explain to me what I am doing wrong and how I should set the 
> values for each dictionary?

Your code has two for loops, one that reads ERCC.txt into a dict, and
one that reads blast.txt into a dict. The first assigns to
`transcript`, the second to `blasttranscript`. When the loops are
finished, you're using the _last_ value set for both `transcript` and
`blasttranscript`. So, really, you want _three_ loops: two to load the
files into dicts, then another to compare the two of them. If the
transcripts in blast.txt are guaranteed to be a subset of ERCC.txt,
then you could get away with two loops:

# convenience function for splitting lines into values
def get_transcript_and_size(line):
columns = line.strip().split()
return columns[0].strip(), int(columns[1].strip())

# read in blast_file
blast_transcripts = {}
with open('transcript_blast.txt') as blast_file:
# this is a context manager, it'll close the file when it's
finished
for line in blast_file:
blasttranscript, blastsize = get_transcript_and_size(line)
blast_transcripts[blasttranscript] = blastsize

# read in ERCC and compare to blast
with open('transcript_ERCC.txt') as ercc_file, \
 open('Not_sequenced_ERCC_transcript.txt', 'w') as
unknown_transcript, \
 open('transcript_out.txt', 'w') as out_file:
# this is called a _nested_ context manager, and requires 2.7+
or 3.1+
for line in ercc_file:
ercctranscript, erccsize = get_transcript_and_size(line)
if ercctranscript not in blast_transcripts:
print >> unknown_transcript, ercctranscript
else:
is_ninety_percent = blast_transcripts[ercctranscript]
>= 0.9*erccsize
print >> out_file, ercctranscript, is_ninety_percent

I've cleaned up your code a bit, using more similar naming schemes and
the same open/write procedures for all file access. Generally, any
time you're repeating code, you should stick it into a function and
use that instead, like the `get_transcript_and_size` func. If the
columns in your two files are separated by tabs, or always by the same
number of spaces, you can simplify this even further by using the csv
module: http://docs.python.org/2/library/csv.html

Hope this helps.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-04 Thread Carlos Nepomuceno
> Date: Tue, 4 Jun 2013 18:28:17 -0700
> Subject: Re: Changing filenames from Greeklish => Greek (subprocess complain)
> From: wuwe...@gmail.com
[...]
> Just a reminder to everyone that the OP originally went by the name of
> Ferrous Cranus:
> http://redwing.hutman.net/~mreed/warriorshtm/ferouscranus.htm
> 
> He's told there's a missing parenthesis, he dismisses the claim. He's
> given code that demonstrates the missing parenthesis, and he acts
> confused. The list is rapidly becoming his support group for _his
> business_, and the bulk of it has very little to do with Python
> itself.
> 
> I've been struggling for a month to get an inheritance chain working
> with fresnel lenses, should I be posting every single bug I hit here
> every 10 minutes then bump them 10 minutes later when no one responds?
> Is that what the list is for now? We don't do people's home work for
> them, so why are we doing his _work_ for him?

I've had once this naive expectation that his obduracy would end! lol


  -- 
http://mail.python.org/mailman/listinfo/python-list


Issue values dictionary

2013-06-04 Thread claire morandin
 I have two text file with a bunch of transcript name and their corresponding 
length, it looks like this:
ERCC.txt
ERCC-2  1061
ERCC-3  1023
ERCC-4  523
ERCC-9  984
ERCC-00012  994
ERCC-00013  808
ERCC-00014  1957
ERCC-00016  844
ERCC-00017  1136
ERCC-00019  644
blast.tx
ERCC-2  1058
ERCC-3  1017
ERCC-4  519
ERCC-9  977
ERCC-00019  638
ERCC-00022  746
ERCC-00024  134
ERCC-00024  126
ERCC-00024  98
ERCC-00025  445

I want to compare the length of the transcript and see if the length in 
blast.txt is at least 90% of the length in ERCC.txt for the corresponding 
transcript name ( I hope I am clear!) 
So I wrote the following script:
ercctranscript_size = {}
for line in open('ERCC.txt'):
columns = line.strip().split()
transcript = columns[0]
size = columns[1]
ercctranscript_size[transcript] = int(size)

unknown_transcript = open('Not_sequenced_ERCC_transcript.txt', 'w')
blast_file = open('blast.txt')
out_file = open ('out.txt', 'w')

blast_transcript = {}
blast_file.readline()
for line in blast_file:
blasttranscript = columns[0].strip()
blastsize = columns[1].strip()
blast_transcript[blasttranscript] = int(blastsize)

blastsize = blast_transcript[blasttranscript]
size = ercctranscript_size[transcript]
print size 
if transcript not in blast_transcript:
unknown_transcript.write('{0}\n'.format(transcript))
else:
size = ercctranscript_size[transcript]
if blastsize >= 0.9*size:
print >> out_file, transcript, True
else:
print >> out_file, transcript, False

But I have a problem storing all size length to the value size as it is always 
comes back with the last entry. 
Could anyone explain to me what I am doing wrong and how I should set the 
values for each dictionary? I am really new to python and this is my first 
script 

Thanks for your help everybody!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Bools and explicitness [was Re: PyWart: The problem with "print"]

2013-06-04 Thread alex23
On Jun 5, 2:09 am, Rick Johnson  wrote:
> This is how you design a language for consistency and readability.

Great! Now you can shut up and get back to work on RickPython4000.
Come back and let us know all about it when it's done.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-04 Thread alex23
On Jun 5, 5:32 am, Νικόλαος Κούρας  wrote:
> Lele the output of:
>
> stmt = "cur.execute('''SELECT url FROM files WHERE url = %s''', ( fullpath, )"
> chars_count = Counter(stmt)
> print("Number of '(': %d" % chars_count['('])
> print("Number of ')': %d" % chars_count[')'])
>
> is:
>
> Number of '(': 2 Number of ')': 1
>
> What do you make out of this please?

Just a reminder to everyone that the OP originally went by the name of
Ferrous Cranus:
http://redwing.hutman.net/~mreed/warriorshtm/ferouscranus.htm

He's told there's a missing parenthesis, he dismisses the claim. He's
given code that demonstrates the missing parenthesis, and he acts
confused. The list is rapidly becoming his support group for _his
business_, and the bulk of it has very little to do with Python
itself.

I've been struggling for a month to get an inheritance chain working
with fresnel lenses, should I be posting every single bug I hit here
every 10 minutes then bump them 10 minutes later when no one responds?
Is that what the list is for now? We don't do people's home work for
them, so why are we doing his _work_ for him?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Python-Dev] Do you consider Python a 4GL? Why (not)?

2013-06-04 Thread Dan Stromberg
On Tue, Jun 4, 2013 at 4:53 PM, Carlos Nepomuceno <
carlosnepomuc...@outlook.com> wrote:

> Do you consider Python a 4GL? Why (not)?
>

By the wikipedia definition of 4GL and 5GL, I'd say Python is neither.  And
it's not a VHLL either, again according to the wikipedia definition.  But
IMO it is too high level to be a traditional 3GL too.

Perhaps "Scripting language" is the best general category we have that
Python fits into.  But I hope not.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to increment date by week?

2013-06-04 Thread Skip Montanaro
Check out the rrule module in the python-dateutil package:

http://labix.org/python-dateutil
https://pypi.python.org/pypi/python-dateutil

Skip
-- 
http://mail.python.org/mailman/listinfo/python-list


Multiple Python one-liners

2013-06-04 Thread vasudevram
http://jugad2.blogspot.com/2013/06/multiple-python-one-liners.html

Some interesting and useful one-liners there ...
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Do you consider Python a 4GL? Why (not)?

2013-06-04 Thread Carlos Nepomuceno
I don't have an opinion yet, but I've found contradictory evidence from many 
sources, such as:

"A domain-specific language (DSL) is a type of programming language or 
specification language in software development and domain engineering dedicated 
to a particular problem domain,
[...]
The opposite is:
a general-purpose programming language, such as C, Java or 
Python,"http://en.wikipedia.org/wiki/Domain-specific_programming_language

Since, 4GL is considered a subset of DSLs, this wiki page doesn't consider 
Python a 4GL.

Is is true? Why???
  -- 
http://mail.python.org/mailman/listinfo/python-list


Re: Do you consider Python a 4GL? Why (not)?

2013-06-04 Thread Mark Lawrence

On 05/06/2013 01:14, Tim Chase wrote:

On 2013-06-05 02:53, Carlos Nepomuceno wrote:

Do you consider Python a 4GL? Why (not)?


Of course it's a 4GL ("4 Guido Language").  You think he wrote it for
somebody else?

Unless you have some magical list of criteria that makes your own
definition of "4GL", in which case you should look at your list of
those "4GL" definitions and weigh them against publicly known facts
about Python, yielding the answer to your question. :-P

-tkc




"Publicly known facts" as in Python is a weakly typed language? :)

--
"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: Do you consider Python a 4GL? Why (not)?

2013-06-04 Thread Tim Chase
On 2013-06-05 02:53, Carlos Nepomuceno wrote:
> Do you consider Python a 4GL? Why (not)?

Of course it's a 4GL ("4 Guido Language").  You think he wrote it for
somebody else?

Unless you have some magical list of criteria that makes your own
definition of "4GL", in which case you should look at your list of
those "4GL" definitions and weigh them against publicly known facts
about Python, yielding the answer to your question. :-P

-tkc


-- 
http://mail.python.org/mailman/listinfo/python-list


Do you consider Python a 4GL? Why (not)?

2013-06-04 Thread Carlos Nepomuceno
Do you consider Python a 4GL? Why (not)?
  -- 
http://mail.python.org/mailman/listinfo/python-list


Re: Bools and explicitness [was Re: PyWart: The problem with "print"]

2013-06-04 Thread Mark Lawrence

On 05/06/2013 00:21, Rick Johnson wrote:
[snip]

Would you be kind enough not to smoke too much wacky baccy before 
posting, 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: Bools and explicitness [was Re: PyWart: The problem with "print"]

2013-06-04 Thread Rick Johnson
On Jun 4, 12:42 pm, Ian Kelly  wrote:

> > By this manner, we can roll three common tests into one
> > method:
> > * Boolean conversion
> > * member truthiness for iterables
> > * type checking
> How exactly does this is_valid method perform the first two?  Are you
> suggesting that an empty sequence should not be considered "valid"?

I'm suggesting that the rules for Python's current "implicit
conversion to Boolean" simply be moved into a "explicit function"
named "isvalid", that also does a type check. Here is some Python code
that might help you understand.

py> def isvalid(object_, type_):
... if isinstance(object_, type_) and object_:
... return True
... return False
py> isvalid([], list)
False
py> isvalid([1], list)
True
py> isvalid(0, int)
False
py> isvalid(1, int)
True
py> isvalid({}, dict)
False
py> isvalid("", str)
False
py> isvalid(" ", str)
True

Now, let's go back to my earlier example of where i was expecting a
list but got a string instead. If i use Python's current implicit
conversion to Boolean my code will do something i don't want it to do.

py> lst = " "
py> if lst:
... print("I'm a liar")
... else:
... print("I'm honest")
I'm a liar

But unlike this simple example (which failed quickly) in the real
world, it may not fail for a long time. And when it does fail, you
will be pulling your hair out tracking down the origin of the bug. If
however i use my "isvalid" function, my conditional will not lie to
me:

py> lst = " "
py> if isvalid(lst, list):
... print("I'm a liar")
... else:
... print("I'm honest")
I'm honest

Now. You're not always going to need to "isvalid" function. Sometimes
you just need to test type, sometimes you just need convert to
Boolean, and sometimes you can just fly by the seat of your pants. The
point is, remove implicitly and inject explicitly.

Furthermore: If the current "implicit conversion to Boolean" can be
optimized by Python, then there is no reason why an explicit "isvalid"
function cannot -- any talk to the contrary is just BS.

If you still feel that this idea is garbage, then, keep on writing
your sloppy code. My proposal is the best method to handle the
problems that arise with duck typed languages in a manner that is not
restrictive or laborious -- it's actually quite elegant.

*school-bell-rings*
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: How to increment date by week?

2013-06-04 Thread Carlos Nepomuceno
> Date: Tue, 4 Jun 2013 14:31:07 -0700
> Subject: How to increment date by week?
> From: r90...@gmail.com
> To: python-list@python.org
> 
>Starting on any day/date, I would like to create a one year list, by week 
> (start date could be any day of week).  Having a numerical week index in 
> front of date, ie 1-52, would be a bonus.  
>ie, 1.  6/4/2013
>2.  6/11/2013
>3.  6/18/2013etc to # 52.
> 
>And to save that result to a file.
>Moving from 2.7 to 3.3
> TIA

YAS:

import datetime
today = datetime.datetime.today()
week  = datetime.timedelta(weeks=1)

f=open('output.txt','w')
for i in range(52):
f.write((today+i*week).strftime(str(i+1)+'. %Y-%m-%d\n'))
f.close()

  -- 
http://mail.python.org/mailman/listinfo/python-list


Re: Apache and suexec issue that wont let me run my python script

2013-06-04 Thread Chris Angelico
On Wed, Jun 5, 2013 at 3:12 AM, Νικόλαος Κούρας  wrote:
> I know what full root access mean.
> I also trust you.
> I'm hopeless man, its 1 week now dealing with this.

The call is strong... I could rule the galaxy alongside my father...
I've searched my feelings, and I know this to be true!

Okay. I accept. I'll do as I promised. Might be interesting, and
educative - for someone, at least.

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to increment date by week?

2013-06-04 Thread John Gordon
In  PieGuy 
 writes:

>Starting on any day/date, I would like to create a one year list, by week 
> (start date could be any day of week).  Having a numerical week index in 
> front of date, ie 1-52, would be a bonus.  
>ie, 1.  6/4/2013
>2.  6/11/2013
>3.  6/18/2013etc to # 52.

>And to save that result to a file.
>Moving from 2.7 to 3.3
> TIA

from datetime import date, timedelta

the_date = date(year=2013, month=6, day=4)

print "%d. %s" % (1, the_date)

for n in range(2, 53):
the_date = the_date + timedelta(days=7)
print "%d. %s" % (n, the_date)

-- 
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: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-04 Thread Chris Angelico
On Wed, Jun 5, 2013 at 6:03 AM, Νικόλαος Κούρας  wrote:
>>UnicodeEncodeError: 'utf-8' codec can't encode character '\udcc5' in position 
>>>61: surrogates not allowed
>
> This indicates that i'am reading the filenames in a different encoding than 
> what they actually are? What is i try to use bytes for path specifications, 
> and have Python decode them in 'utf-8' ?
>
> fullpaths.add( os.path.join(root, fullpath).encode('utf-8') )

For some reason you have an invalid Unicode codepoint in your string. Fix that.

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lstrip problem - beginner question

2013-06-04 Thread Dave Angel

On 06/04/2013 12:01 PM, Mark Lawrence wrote:

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 :)



Mark:
The OP is posting from googlegroups, just using a yahoo return address. 
 So you just have one buggy provider to hate, not two.


>>
>>> 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:
>>

madmax...@yahoo.it:

If you must use googlegroups, at least fix the double-posting and 
double-spacing bugs it has.  Start by reading:


 http://wiki.python.org/moin/GoogleGroupsPython




--
DaveA
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to increment date by week?

2013-06-04 Thread Giorgos Tzampanakis
On 2013-06-04, PieGuy wrote:

>Starting on any day/date, I would like to create a one year list, by
>week (start date could be any day of week).  Having a numerical week
>index in front of date, ie 1-52, would be a bonus.  
>ie, 1.  6/4/2013
>2.  6/11/2013
>3.  6/18/2013etc to # 52.

date2 = date1 + datetime.timedelta(7)

-- 
Real (i.e. statistical) tennis and snooker player rankings and ratings:
http://www.statsfair.com/ 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to increment date by week?

2013-06-04 Thread Tim Chase
On 2013-06-04 14:31, PieGuy wrote:
>Starting on any day/date, I would like to create a one year
> list, by week (start date could be any day of week).  Having a
> numerical week index in front of date, ie 1-52, would be a bonus.
> ie, 1.  6/4/2013 2.  6/11/2013 3.  6/18/2013etc to # 52.

 import datetime
 start = datetime.date.today()
 for i in range(53):
   dt = start + datetime.timedelta(days=7*i)
   result = "%i. %s" % (
 i+1,
 dt.strftime('%m/%d/%Y')
 )
   do_something_with(result)

-tkc




-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to get an integer from a sequence of bytes

2013-06-04 Thread Chris Angelico
On Wed, Jun 5, 2013 at 5:51 AM, Joshua Landau
 wrote:
> On 4 June 2013 14:39, Grant Edwards  wrote:
>> On 2013-06-03, Dan Stromberg  wrote:
>>> 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.
> )
>
> *) for the bracket not in the reply
>
> Sorry.

So... can we cite http://xkcd.com/859/ in two threads at once, or does
that create twice as much tension?

Once an XKCD is un-cited, will it be garbage collected promptly, or do
they contain refloops?

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to increment date by week?

2013-06-04 Thread Joshua Landau
On 4 June 2013 22:31, PieGuy  wrote:
>Starting on any day/date, I would like to create a one year list, by week 
> (start date could be any day of week).  Having a numerical week index in 
> front of date, ie 1-52, would be a bonus.
>ie, 1.  6/4/2013
>2.  6/11/2013
>3.  6/18/2013etc to # 52.
>
>And to save that result to a file.
>Moving from 2.7 to 3.3
> TIA

What have you tried? What are you stuck on? We're not here to do your
work for you.

See http://docs.python.org/3/library/datetime.html for where to get started.
-- 
http://mail.python.org/mailman/listinfo/python-list


How to increment date by week?

2013-06-04 Thread PieGuy
   Starting on any day/date, I would like to create a one year list, by week 
(start date could be any day of week).  Having a numerical week index in front 
of date, ie 1-52, would be a bonus.  
   ie, 1.  6/4/2013
   2.  6/11/2013
   3.  6/18/2013etc to # 52.

   And to save that result to a file.
   Moving from 2.7 to 3.3
TIA
-- 
http://mail.python.org/mailman/listinfo/python-list


Problems with serial port interface

2013-06-04 Thread lionelgreenstreet
Hi,
i'm programming in python for the first time: i want to create a serial port 
reader. I'm using python3.3 and pyQT4; i'm using also pyserial.
Below a snippet of the code:

class CReader(QThread):
def start(self, ser, priority = QThread.InheritPriority):
self.ser = ser
QThread.start(self, priority)
self._isRunning = True
self.numData=0;
  
def run(self):
print("Enter Creader")
while True:
if self._isRunning:
try:
data = self.ser.read(self.numData)
n = self.ser.inWaiting()
if n:
data = self.ser.read(n)
self.emit(SIGNAL("newData(QString)"), 
data.decode('cp1252', 'ignore'))
self.ser.flushInput()
except:
pass
else:
return

def stop(self):
self._isRunning = False
self.wait()
 
This code seems work well, but i have problems in this test case:

+baud rate:19200
+8/n/1
+data transmitted: 1 byte every 5ms

After 30seconds (more or less) the program crashes: seems a buffer problem, but 
i'm not really sure. 
What's wrong?
Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [RELEASED] Python 2.7.5

2013-06-04 Thread Fábio Santos
On 4 Jun 2013 21:47, "Joshua Landau"  wrote:
>
> On 4 June 2013 00:12, Mark Lawrence  wrote:
> > On 03/06/2013 23:37, Carlos Nepomuceno wrote:
> >> What still doesn't work in Python 3?
> >
> > http://python3wos.appspot.com/
>
> Don't take this list too seriously - some of those do have fully
> working and stable Python 3 packages that just aren't in pip, like
> python-daemon.

Also, django's py3k support is experimental for now.

https://docs.djangoproject.com/en/dev/releases/1.5/ (see overview, second
paragraph)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [RELEASED] Python 2.7.5

2013-06-04 Thread Joshua Landau
On 4 June 2013 00:12, Mark Lawrence  wrote:
> On 03/06/2013 23:37, Carlos Nepomuceno wrote:
>> What still doesn't work in Python 3?
>
> http://python3wos.appspot.com/

Don't take this list too seriously - some of those do have fully
working and stable Python 3 packages that just aren't in pip, like
python-daemon.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-04 Thread Fábio Santos
On 4 Jun 2013 21:18, "Νικόλαος Κούρας"  wrote:
>
> Lele the output of:
>
> stmt = "cur.execute('''SELECT url FROM files WHERE url = %s''', (
fullpath, )"
> chars_count = Counter(stmt)
> print("Number of '(': %d" % chars_count['('])
> print("Number of ')': %d" % chars_count[')'])
>
> is:
>
> Number of '(': 2 Number of ')': 1
>
> What do you make out of this please?

He couldn't have been more obvious. You are missing a closing parenthesis.

http://xkcd.com/859/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: create new python file

2013-06-04 Thread Tobiah

So, can i program within just by the print statement? Or do i have to do 
something else.


it is completely indecipherable (to me at least) what you are saying,
leave aside any issues with python.


He said, "Oh, so writing python statements into a text file is as
simple as printing them, referencing a handle to the file?  That seems
simpler than I had imagined.  Is there nothing else that I must do
in order to achieve my goal?".




--
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-04 Thread Νικόλαος Κούρας
Lele the output of:

stmt = "cur.execute('''SELECT url FROM files WHERE url = %s''', ( fullpath, )" 
chars_count = Counter(stmt) 
print("Number of '(': %d" % chars_count['('])
print("Number of ')': %d" % chars_count[')'])

is:

Number of '(': 2 Number of ')': 1

What do you make out of this please?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-04 Thread Νικόλαος Κούρας
>UnicodeEncodeError: 'utf-8' codec can't encode character '\udcc5' in position 
>>61: surrogates not allowed

This indicates that i'am reading the filenames in a different encoding than 
what they actually are? What is i try to use bytes for path specifications, and 
have Python decode them in 'utf-8' ?

fullpaths.add( os.path.join(root, fullpath).encode('utf-8') )

Will this work? As Michael said encoding is a process which you take unicode 
characters and conver them to bytestream using some charset(utf8 here)

Will this work?
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: create new python file

2013-06-04 Thread Carlos Nepomuceno


> Date: Tue, 4 Jun 2013 11:54:52 -0700
> Subject: Re: create new python file
> From: kakararunachalserv...@gmail.com
[...]
> > 
> > > So, can i program within just by the print statement? Or do i have to do 
> > > something else.
> > 
> > 
> > 
> > it is completely indecipherable (to me at least) what you are saying,
> > 
> > leave aside any issues with python.
> 
> God! Thanks "Dr." Rusi!

lol
  -- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to get an integer from a sequence of bytes

2013-06-04 Thread Joshua Landau
On 4 June 2013 14:39, Grant Edwards  wrote:
> On 2013-06-03, Dan Stromberg  wrote:
>> 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.
)

*) for the bracket not in the reply

Sorry.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Beginner question

2013-06-04 Thread Joshua Landau
On 4 June 2013 04:39,   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()

I'm going to look directly at the code for my comment, here, and
explain what's up. I imagine you were given this code to "fix up",
I'll lead you through the steps.



> import random

You only use "random.choice", never anything else, so in this case I'd
be tempted to do:
> from random import choice

This is *entirely optional*: I tend to do quite a lot of "from
 import " but others prefer to be more explicit about
where things come from; your choice.



> def partdeux():

Other than the atrocious name this is as simple as it gets to define a
function - you should like that it's a function, though.



> print('''A man lunges at you with a knife!
> Do you DUCK or PARRY?''')

This is iffy! Triple-quotes? Personally this is a really bad time to
use them - they break indentation and whatnot. I'd write:

>print('A man lunges at you with a knife!')
>print('Do you DUCK or PARRY?')

This, in my opinion, is much nicer. But we haven't "simplified" much yet.



> option1=('duck')
> option2=('parry')
> optionsindex=[option1, option2]

There are two things off about this. Firstly, no-one should be so
addicted to brackets to use them here, and you should space variables.
> option1 = 'duck'
> option2 = 'parry'

BUT this is not needed anyway. The next line puts both of these in a
variable. You can add them straight in:
> optionsindex = ['duck', 'parry']

There are some things wrong though:
1) *Never* lie. This is not an "index" of any sort, unless you're
referring to one of these:
[http://shop.pageprotectors.com/images/Index-Ring-Binder-2-Rings-Recipe-3x5-Card.jpg]
This should be named "options" or, better, "valid_responses".

2) You write "Do you DUCK or PARRY?". None of this suggests uppercase.
We shall deal with this later.

Thus:
> valid_responses = ['duck', 'parry']


> randomizer=random.choice(optionsindex)
> while randomizer==option1:
...
> while randomizer==option2:

This is odd! What do you think this does? This says that you choose an
option, "duck" or "parry". If it is "duck", then do A. If it is
"parry", then do B. But why would a computer choose options like that?
Surely it's better to do:

(I'm properly spacing it as I go along, by the way)
>randomizer = random.choice([True, False])
>while randomizer:
...
>while not randomizer:

Oh, that's odd! As randomizer never changes after you set it, you can
be sure that the "while randomizer" is equivalent to "while True" or
"while False". This means it will loop forever without a break.
Looking at the breaks it is clear that *all paths lead to a break*. A
while *LOOP* should only ever be used to *LOOP*. This makes the
looping redundant.

Thus remove the breaks and use:
>randomizer = random.choice([True, False])
>if randomizer:
...
>if not randomizer:

which can be better written:
>if random.choice([True, False]):
...
>else:
(BUT you may have to write "if choice([True, False]):" if you've
followed all of my advice)


> if input() in option1:
"option1" no longer exists, so this is now written:
> if input() in valid_responses[0]:
BUT why "in"? You want to check whether that *equals* the response,
not whether that is *in* the response:
> if input() == valid_responses[0]:


> else:
> print('he stabs you')
Why "else"? This means that if you wrote "Seppuku" *he'd* stab you.
You want to check that you actually wrote the right thing!
> elif input() == valid_responses[1]:
> print('he stabs you')
This does not work, but we'll fix it later.


> if input() in option2:
For the same reason, change this to:
>if input() == valid_responses[1]:


> else:
> print('he stabs you')
and this to:
> elif input() == valid_responses[0]:
> print('he stabs you')


The rest is better. That leaves you with a much nicer looking function:

### START CODE ###
from random import choice

def partdeux():
print("A man lunges at you with a knife!")
print("Do you DUCK or PARRY?")

valid_responses = ["duck", "parry"]

if choice([True, False]):
if input() == valid_responses[0]:
print('he tumbles over you')
elif i

Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-04 Thread Lele Gaifax
Νικόλαος Κούρας  writes:

> Τη Τρίτη, 4 Ιουνίου 2013 9:18:29 μ.μ. UTC+3, ο χρήστης Lele Gaifax έγραψε:
>> Νικόλαος Κούρας  writes:
>
>> >>> from collections import Counter
>> >>> stmt = "cur.execute('''SELECT url FROM files WHERE url = %s''', ( 
>> >>> fullpath, )" 
>> >>> chars_count = Counter(stmt)
>> >>> print("Number of '(': %d" % chars_count['('])
>> >>> print("Number of ')': %d" % chars_count[')'])
>> Number of '(': 2 
>> Number of ')': 1
>
>
> Hello Lele, you have proven helpfull many times lets hope once more:

With due respect, you need to *improve* your ability to *understand*
what people answer to your questions, otherwise it is a double (at a
minimum) waste of time. 

The code above was my (failed) attempt to focus your attention on why
one of your scripts raised a SyntaxError: translating that code in plain
english, that line (the "stmt" variable above) contains *two* open
brackets, and *one* close bracket.

ciao, lele.
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
l...@metapensiero.it  | -- Fortunato Depero, 1929.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-04 Thread Νικόλαος Κούρας
Τη Τρίτη, 4 Ιουνίου 2013 9:45:05 μ.μ. UTC+3, ο χρήστης Chris "Kwpolska" Warrick 
έγραψε:
> On Tue, Jun 4, 2013 at 8:27 PM, Νικόλαος Κούρας  wrote:
> 
> > 2. No idea wht is flask or pyramid or wsgi
> 
> 
> 
> http://lmgtfy.com/?q=flask+python
> 
> http://lmgtfy.com/?q=pyramid+python
> 
> http://lmgtfy.com/?q=wsgi+python
> 
> 
> 
> > 3. Files are located in '/home/nikos/www/data/apps' and they appear in 
> > browser direcory listing. Create an index.html you mean?
> 
> 
> 
> If they do, they are already indexed.  Now link stuff to that
> 
> directory instead of your fancy files.py thing.

No. The file grabbing must be from withing 'files.py' so database inserts 
happen and counter addition takes place.

Also, it is a good torchering to me to leatn about this damn encoding issues 
iam having trouble to all my scripr syear now.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: create new python file

2013-06-04 Thread kakararunachalservice
On Tuesday, June 4, 2013 11:51:46 PM UTC+5:30, rusi wrote:
> On Jun 4, 11:09 pm, kakararunachalserv...@gmail.com wrote:
> 
> > Thank you so much! Why didn't i thought about that. So, can i program 
> > within just by the print
> 
> > statement? Or do i have to do something else. I'm sorry, i just learning 
> > python. Thanks again!
> 
> 
> 
> If you are just learning python, you almost certainly dont want to do
> 
> what you are asking for.
> 
> So take some time, think through what you want, tell us, without
> 
> worrying too much about the python angle -- we'll handle that side.
> 
> 
> 
> And yes, please spell-n-grammar check your question, if necessary with
> 
> a friend who knows English a bit.  An odd English error here and there
> 
> we can get on with. However with
> 
> 
> 
> > So, can i program within just by the print statement? Or do i have to do 
> > something else.
> 
> 
> 
> it is completely indecipherable (to me at least) what you are saying,
> 
> leave aside any issues with python.

God! Thanks "Dr." Rusi!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-04 Thread Chris “Kwpolska” Warrick
On Tue, Jun 4, 2013 at 8:27 PM, Νικόλαος Κούρας  wrote:
> 2. No idea wht is flask or pyramid or wsgi

http://lmgtfy.com/?q=flask+python
http://lmgtfy.com/?q=pyramid+python
http://lmgtfy.com/?q=wsgi+python

> 3. Files are located in '/home/nikos/www/data/apps' and they appear in 
> browser direcory listing. Create an index.html you mean?

If they do, they are already indexed.  Now link stuff to that
directory instead of your fancy files.py thing.

--
Kwpolska  | 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)

2013-06-04 Thread Νικόλαος Κούρας
Τη Τρίτη, 4 Ιουνίου 2013 9:18:29 μ.μ. UTC+3, ο χρήστης Lele Gaifax έγραψε:
> Νικόλαος Κούρας  writes:

> >>> from collections import Counter
> >>> stmt = "cur.execute('''SELECT url FROM files WHERE url = %s''', ( 
> >>> fullpath, )" 
> >>> chars_count = Counter(stmt)
> >>> print("Number of '(': %d" % chars_count['('])
> >>> print("Number of ')': %d" % chars_count[')'])
> Number of '(': 2 
> Number of ')': 1


Hello Lele, you have proven helpfull many times lets hope once more:

# 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) )


stmt = "cur.execute('''SELECT url FROM files WHERE url = %s''', ( fullpath, )" 
chars_count = Counter(stmt) 
print("Number of '(': %d" % chars_count['('])
print("Number of ')': %d" % chars_count[')'])

sys.exit(0)

outputs this:


http://superhost.gr/cgi-bin/files.py

I dont even understand what that means though.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Source code as text/plain

2013-06-04 Thread Carlos Nepomuceno
Thank you!

> Date: Tue, 4 Jun 2013 17:51:08 +0200
> From: andiper...@gmail.com
> To: python-list@python.org
> Subject: 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
  -- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-04 Thread Νικόλαος Κούρας
Τη Τρίτη, 4 Ιουνίου 2013 8:53:38 μ.μ. UTC+3, ο χρήστης Chris "Kwpolska" Warrick 
έγραψε:
> On Tue, Jun 4, 2013 at 7:23 PM, Νικόλαος Κούρας  wrote:
> 
> > What on eart is this damn error: Michael tried to explain to me about 
> > surrogates but dont think i understand it.
> 
> >
> 
> > Encoding giving me trouble years now.
> 
> >
> 
> > [Tue Jun 04 20:19:53 2013] [error] [client 46.12.95.59] Original exception 
> > was:
> 
> > [Tue Jun 04 20:19:53 2013] [error] [client 46.12.95.59] Traceback (most 
> > recent call last):
> 
> > [Tue Jun 04 20:19:53 2013] [error] [client 46.12.95.59]   File "files.py", 
> > line 72, in 
> 
> > [Tue Jun 04 20:19:53 2013] [error] [client 46.12.95.59] 
> > cur.execute('''SELECT url FROM files WHERE url = %s''', (fullpath,) )
> 
> > [Tue Jun 04 20:19:53 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 20:19:53 2013] [error] [client 46.12.95.59] query = 
> > query.encode(charset)
> 
> > [Tue Jun 04 20:19:53 2013] [error] [client 46.12.95.59] UnicodeEncodeError: 
> > 'utf-8' codec can't encode character '\\udcd3' in position 61: surrogates 
> > not allowed
> 
> >
> 
> >
> 
> >
> 
> > PLEASE TELL EM WHAT TO TRY, PLEASE FOR THE LOVE OF GOD, IAM SO FRUSTRATED 
> > NOT BEING ABLE TO DEAL WITH THIS.
> 
> > --
> 
> > http://mail.python.org/mailman/listinfo/python-list
> 
> 
> 
> 1. Try re-naming the files to real utf-8.  Make sure your terminal
> 
> works on UTF-8 characters.
> 
> 2. Get rid of your bullshit system and use Flask or Pyramid.  It will
> 
> make your life much easier.
> 
> 3. Put the files in a directory on your server and tell Apache to
> 
> create an index, making your life easier, but not as easy as it would
> 
> if you did (2) and anywhere near as easy as (2) and (3) combined.
> 
> --
> 
> Kwpolska  | GPG KEY: 5EAAEA16
> 
> stop html mail| always bottom-post
> 
> http://asciiribbon.org| http://caliburn.nl/topposting.html


1. local is set to utf-8 and the renaming from english to greek happnend in the 
webhost.

2. No idea wht is flask or pyramid or wsgi

3. Files are located in '/home/nikos/www/data/apps' and they appear in browser 
direcory listing. Create an index.html you mean?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: create new python file

2013-06-04 Thread rusi
On Jun 4, 11:09 pm, kakararunachalserv...@gmail.com wrote:
> Thank you so much! Why didn't i thought about that. So, can i program within 
> just by the print
> statement? Or do i have to do something else. I'm sorry, i just learning 
> python. Thanks again!

If you are just learning python, you almost certainly dont want to do
what you are asking for.
So take some time, think through what you want, tell us, without
worrying too much about the python angle -- we'll handle that side.

And yes, please spell-n-grammar check your question, if necessary with
a friend who knows English a bit.  An odd English error here and there
we can get on with. However with

> So, can i program within just by the print statement? Or do i have to do 
> something else.

it is completely indecipherable (to me at least) what you are saying,
leave aside any issues with python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-04 Thread Lele Gaifax
Νικόλαος Κούρας  writes:

> root@nikos [~]# [Tue Jun 04 19:50:16 2013] [error] [client 46.12.95.59]   
> File "files.py", line 72
> [Tue Jun 04 19:50:16 2013] [error] [client 46.12.95.59] data = 
> cur.fetchone()#URL is unique, so should only be one
> [Tue Jun 04 19:50:16 2013] [error] [client 46.12.95.59]^
> [Tue Jun 04 19:50:16 2013] [error] [client 46.12.95.59] SyntaxError: invalid 
> syntax

Some kind soul already said you the reason. What follows is the longest
way I could think to spot your error:

>>> from collections import Counter
>>> stmt = "cur.execute('''SELECT url FROM files WHERE url = %s''', ( fullpath, 
>>> )"
>>> chars_count = Counter(stmt)
>>> print("Number of '(': %d" % chars_count['('])
>>> print("Number of ')': %d" % chars_count[')'])
Number of '(': 2
Number of ')': 1

ciao, lele.
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
l...@metapensiero.it  | -- Fortunato Depero, 1929.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: create new python file

2013-06-04 Thread kakararunachalservice
On Tuesday, June 4, 2013 11:14:32 PM UTC+5:30, Gary Herron wrote:
> On 06/04/2013 09:07 AM, kakararunachalserv...@gmail.com wrote:
> 
> > Hi,
> 
> > Can anyone please tell me how to dynamically create a new python file 
> > within a program???
> 
> 
> 
> What do you mean by a "python file"?   If you mean a text file 
> 
> containing python code, then create it like any other text file. For 
> 
> instance:
> 
> 
> 
>  with open("Hello.py", "w") as f:
> 
>  print("print('Hello world')\n", file=f)
> 
> 
> 
> will create a file containing a simple one-line Python program.
> 
> 
> 
> If you meant something else, then please take the time to provide more 
> 
> detail.
> 
> 
> 
> Gary Herron
> 
> 
> 
> 
> 
> -- 
> 
> Dr. Gary Herron
> 
> Department of Computer Science
> 
> DigiPen Institute of Technology
> 
> (425) 895-4418


Thank you so much! Why didn't i thought about that. So, can i program within 
just by the print statement? Or do i have to do something else. I'm sorry, i 
just learning python. Thanks again!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-04 Thread Chris “Kwpolska” Warrick
On Tue, Jun 4, 2013 at 7:23 PM, Νικόλαος Κούρας  wrote:
> What on eart is this damn error: Michael tried to explain to me about 
> surrogates but dont think i understand it.
>
> Encoding giving me trouble years now.
>
> [Tue Jun 04 20:19:53 2013] [error] [client 46.12.95.59] Original exception 
> was:
> [Tue Jun 04 20:19:53 2013] [error] [client 46.12.95.59] Traceback (most 
> recent call last):
> [Tue Jun 04 20:19:53 2013] [error] [client 46.12.95.59]   File "files.py", 
> line 72, in 
> [Tue Jun 04 20:19:53 2013] [error] [client 46.12.95.59] 
> cur.execute('''SELECT url FROM files WHERE url = %s''', (fullpath,) )
> [Tue Jun 04 20:19:53 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 20:19:53 2013] [error] [client 46.12.95.59] query = 
> query.encode(charset)
> [Tue Jun 04 20:19:53 2013] [error] [client 46.12.95.59] UnicodeEncodeError: 
> 'utf-8' codec can't encode character '\\udcd3' in position 61: surrogates not 
> allowed
>
>
>
> PLEASE TELL EM WHAT TO TRY, PLEASE FOR THE LOVE OF GOD, IAM SO FRUSTRATED NOT 
> BEING ABLE TO DEAL WITH THIS.
> --
> http://mail.python.org/mailman/listinfo/python-list

1. Try re-naming the files to real utf-8.  Make sure your terminal
works on UTF-8 characters.
2. Get rid of your bullshit system and use Flask or Pyramid.  It will
make your life much easier.
3. Put the files in a directory on your server and tell Apache to
create an index, making your life easier, but not as easy as it would
if you did (2) and anywhere near as easy as (2) and (3) combined.
--
Kwpolska  | 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: create new python file

2013-06-04 Thread Gary Herron

On 06/04/2013 09:07 AM, kakararunachalserv...@gmail.com wrote:

Hi,
Can anyone please tell me how to dynamically create a new python file within a 
program???


What do you mean by a "python file"?   If you mean a text file 
containing python code, then create it like any other text file. For 
instance:


with open("Hello.py", "w") as f:
print("print('Hello world')\n", file=f)

will create a file containing a simple one-line Python program.

If you meant something else, then please take the time to provide more 
detail.


Gary Herron


--
Dr. Gary Herron
Department of Computer Science
DigiPen Institute of Technology
(425) 895-4418

--
http://mail.python.org/mailman/listinfo/python-list


Re: Bools and explicitness [was Re: PyWart: The problem with "print"]

2013-06-04 Thread Ian Kelly
On Tue, Jun 4, 2013 at 9:44 AM, Rick Johnson
 wrote:
> 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"

That is *exactly* equivalent to the same test without the bool
function, and it gives the reader zero additional information about
what "lst" is, so it boggles me that you approve of this "if
bool(lst):" monstrosity while decrying the equivalent and slightly
more efficient "if lst:".

I think part of your complaint concerns the fact that the reader must
understand the rules by which a truth value is implicitly obtained
from lst in the statement "if lst:".  But the reader must know the
*same* rules in order to understand the more explicit "if bool(lst):",
so there is no benefit to the latter in that regard either.

> 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.

Caring that the object has a length is not the same as caring about
what the object's length is.  Steven's point stands, that your code
inefficiently asks the object for some property that you don't (yet)
care about.

> "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.

Your "if len(lst) > 0" fails to differentiate lists from strings in
exactly the same way.

> 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.

You said earlier in your post that "bool(lst)" was "explicit enough",
and this is exactly what it does.

> When i am writing code i prefer to be "explicit enough" so
> that IF my assumptions about the exact type of an object are
> incorrect, the code will fail quickly enough that i can
> easily find and correct the problem.

In a duck-typing language you should not be making assumptions about
the "exact type" of an object in the first place.  If I'm writing a
function that receives a list-like argument, then at the *most
specific* I will assume that the object passed in is a MutableSequence
(but since I prefer to keep my functions functional where practical,
more usually I will assume only that the object is an iterable or a
generic sequence).  If the caller wants to pass in a deque or some
user-defined generic MutableSequence instead, then let them do so.  I
will also clearly document that assumption; if the caller can't be
bothered to read the docs and passes in an object that breaks that
assumption, then that's their own damn problem when it doesn't work.
This is a programming language for consenting adults.

> 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!!!

I am more likely to believe that an object is a list based on the
documentation than on the mere fact that it is named "lst".  The
variable *does* have documentation, doesn't it?  If when debugging I
have reason to suspect that the documentation is incorrect or is being
ignored, then I'll add an assertion to test it.

> There must be some method by which we can truth test an
> iterable object and verify it has members, but do so in a
> manner that is valid for all types AND exposes the "expected
> type" in the method name. hmm...

This is nonsense.  If it exposes the "expected type" in the name, then
it can only be valid for that expected type.

> Adding a method like "is_valid" to every object can seem
> logical, however, this can fail just as miserably as
> Python's current implicit bool. And, more disastrously, an
> "is_valid" method is not going to raise an error (where it
> should) because it works for all types.

Actually it sounds completely illogic

Re: Bools and explicitness [was Re: PyWart: The problem with "print"]

2013-06-04 Thread Jason Swails
On Tue, Jun 4, 2013 at 11:44 AM, Rick Johnson
wrote:

>
> 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"


i
f lst:
do_something

is equivalent to

if bool(lst):
   do_something

why not just have your editor autobool so you can spend more time coding
and less time stamping around?  That way the person that finds booled code
more readable can have what he wants and the people that find it less
readable can have what they want.

Win-win

BTW, you should do pointless comparisons like

if condition is True:
do_something

rather than

if condition == True
do_something
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Bools and explicitness [was Re: PyWart: The problem with "print"]

2013-06-04 Thread Ned Batchelder


On 6/4/2013 12:19 PM, Rick Johnson wrote:

On Jun 4, 11:00 am, Chris Angelico  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!



You are mis-using the term "duck typing." It doesn't mean just, "no type 
declarations." It also means, "the type of the value is irrelevant, all 
that matters is what it can do."  Insisting that something be a list (or 
a dict, ...) is unnecessary and counter to the duck-typing philosophy.  
What's important is that you can iterate, or index it, or whatever it is 
you want to do with the list.  The abstract base classes in the 
collections module were designed to help with determining these 
capabilities: 
http://docs.python.org/2/library/collections.html#collections-abstract-base-classes 
Of course, often, it's best just to do what you want to do rather than 
checking first.


Also, I have no idea why [] isn't a "valid" list.  Surely different 
applications will have different needs for what counts as valid once the 
type-check is passed.


--Ned.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-04 Thread Νικόλαος Κούρας
What on eart is this damn error: Michael tried to explain to me about 
surrogates but dont think i understand it.

Encoding giving me trouble years now.

[Tue Jun 04 20:19:53 2013] [error] [client 46.12.95.59] Original exception was:
[Tue Jun 04 20:19:53 2013] [error] [client 46.12.95.59] Traceback (most recent 
call last):
[Tue Jun 04 20:19:53 2013] [error] [client 46.12.95.59]   File "files.py", line 
72, in 
[Tue Jun 04 20:19:53 2013] [error] [client 46.12.95.59] 
cur.execute('''SELECT url FROM files WHERE url = %s''', (fullpath,) )
[Tue Jun 04 20:19:53 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 20:19:53 2013] [error] [client 46.12.95.59] query = 
query.encode(charset)
[Tue Jun 04 20:19:53 2013] [error] [client 46.12.95.59] UnicodeEncodeError: 
'utf-8' codec can't encode character '\\udcd3' in position 61: surrogates not 
allowed



PLEASE TELL EM WHAT TO TRY, PLEASE FOR THE LOVE OF GOD, IAM SO FRUSTRATED NOT 
BEING ABLE TO DEAL WITH THIS.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Beginner question

2013-06-04 Thread Mitya Sirenef

On 06/04/2013 07:53 AM, Carlos Nepomuceno wrote:

>On 4 Jun 2013 12:28,  "Carlos Nepomuceno"  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 what Steven already mentioned, a big advantage is that it's
easier to make a dict if you have a lot of keys that are valid
identifiers, and it's more readable, to boot:

dict(red=1, blue=2, orange=3, violet=4, crimson=5, ...)

VS.

{'red':1, 'blue':2, 'orange':3, 'violet':4, 'crimson':5, ...}

 -m


--
Lark's Tongue Guide to Python: http://lightbird.net/larks/

Although the most acute judges of the witches and even the witches
themselves, were convinced of the guilt of witchery, the guilt nevertheless
was non-existent. It is thus with all guilt.  Friedrich Nietzsche

--
http://mail.python.org/mailman/listinfo/python-list


Re: Apache and suexec issue that wont let me run my python script

2013-06-04 Thread Νικόλαος Κούρας
Τη Τρίτη, 4 Ιουνίου 2013 8:09:18 μ.μ. UTC+3, ο χρήστης Chris Angelico έγραψε:
> On Wed, Jun 5, 2013 at 3:02 AM, Νικόλαος Κούρας  wrote:
> 
> > I'm willing to let someone with full root access to my webhost to see 
> > thigns from the inside.
> 
> >
> 
> > Does someone want to take o allok or at elast tell me what else i need to 
> > try, that hasn't been tried out yet?
> 
> 
> 
> You need to read up on what happens when you enter Dummy Mode and give
> 
> someone full root access to your web host. You really REALLY need to
> 
> understand what that means before you offer random strangers that kind
> 
> of access to someone else's data.
> 
> 
> 
> I've half a mind to take you up on your offer, then go look for
> 
> personal and private info from your clients, and email it to them
> 
> (along with a link to this thread) to point out what's going on.
> 
> 
> 
> ChrisA

I know what full root access mean.
I also trust you.
I'm hopeless man, its 1 week now dealing with this.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Apache and suexec issue that wont let me run my python script

2013-06-04 Thread Chris Angelico
On Wed, Jun 5, 2013 at 3:02 AM, Νικόλαος Κούρας  wrote:
> I'm willing to let someone with full root access to my webhost to see thigns 
> from the inside.
>
> Does someone want to take o allok or at elast tell me what else i need to 
> try, that hasn't been tried out yet?

You need to read up on what happens when you enter Dummy Mode and give
someone full root access to your web host. You really REALLY need to
understand what that means before you offer random strangers that kind
of access to someone else's data.

I've half a mind to take you up on your offer, then go look for
personal and private info from your clients, and email it to them
(along with a link to this thread) to point out what's going on.

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Apache and suexec issue that wont let me run my python script

2013-06-04 Thread Νικόλαος Κούρας
All these popel i host thei websiets are friend fo mine and their webpages all 
of them run witohut any problem.

Only my perosnal webpage, which utilizes python has these kind of issues, the 
other  pages re joomlas and dreamweavers.

Please as you see i have been trying anyhting i thought of and everything i 
googles and been told to.

But still this error insists.

I'm willing to let someone with full root access to my webhost to see thigns 
from the inside.

Does someone want to take o allok or at elast tell me what else i need to try, 
that hasn't been tried out yet?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-04 Thread Νικόλαος Κούρας
Τη Τρίτη, 4 Ιουνίου 2013 6:07:19 μ.μ. UTC+3, ο χρήστης Michael Torrie έγραψε:
> 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)

Thanks for the clear explanation about encode and decode, i never understood it 
more clear.

and yes of course i know that a header must be printed before any other actual 
print statement. Here is how i have it:

-
print( '''Content-type: text/html; charset=utf-8\n''' )

# 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) )


Your unicode explanation is clear but we do have to deal with file's contents 
but rather filenames themselves.

root@nikos [~]# ls -l /home/nikos/www/data/apps/
total 368548
drwxr-xr-x 2 nikos nikos 4096 Jun  4 14:49 ./
drwxr-xr-x 6 nikos nikos 4096 May 26 21:13 ../
-rwxr-xr-x 1 nikos nikos 13157283 Mar 17 12:57 100\ Mythoi\ tou\ Aiswpou.pdf*
-rwxr-xr-x 1 nikos nikos 29524686 Mar 11 18:17 Anekdotologio.exe*
-rw-r--r-- 1 nikos nikos 42413964 Jun  2 20:29 Battleship.exe
-rw-r--r-- 1 nikos nikos   236032 Jun  4 14:10 \323\352\335\370\357\365\ 
\335\355\341\355\ \341\361\351\350\354\374.exe
-rwxr-xr-x 1 nikos nikos 66896732 Mar 17 13:13 Kosmas\ o\ Aitwlos\ -\ 
Profiteies.pdf*
-rw-r--r-- 1 nikos nikos 51819750 Jun  2 20:04 Luxor\ Evolved.exe
-rw-r--r-- 1 nikos nikos 60571648 Jun  2 14:59 Monopoly.exe
-rw-r--r-- 1 nikos nikos  3511233 Jun  4 14:11 \305\365\367\336\ \364\357\365\ 
\311\347\363\357\375.mp3
-rwxr-xr-x 1 nikos nikos  1788164 Mar 14 11:31 Online\ Movie\ Player.zip*
-rw-r--r-- 1 nikos nikos  5277287 Jun  1 18:35 O\ Nomos\ tou\ Merfy\ v1-2-3.zip
-rwxr-xr-x 1 nikos nikos 16383001 Jun 22  2010 Orthodoxo\ Imerologio.exe*
-rw-r--r-- 1 nikos nikos  6084806 Jun  1 18:22 Pac-Man.exe
-rw-r--r-- 1 nikos nikos 25476584 Jun  2 19:50 Scrabble.exe
-rwxr-xr-x 1 nikos nikos 49141166 Mar 17 12:48 To\ 1o\ mou\ vivlio\ gia\ to\ 
skaki.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
root@nikos [~]#
-

As you see the subdirectory 'apps' contain both ebglish and greek lettered 
filenames.

Are those both unicode? Are the filenames of the actuals files also encoded as 
byte streams,much like the contents inside them?

if they are unicode then i really see no trouble when trying to:

cur.execute('''SELECT url FROM files WHERE url = %s''', ( fullpath, )

but his is what i'm still getting:


-

root@nikos [~]# [Tue Jun 04 19:50:16 2013] [error] [client 46.12.95.59]   File 
"files.py", line 72
[Tue Jun 04 19:50:16 2013] [error] [client 46.12.95.59] data = 
cur.fetchone()#URL is unique, so should only be one
[Tue Jun 04 19:50:16 2013] [error] [client 46.12.95.59]^
[Tue Jun 04 19:50:16 2013] [error] [client 46.12.95.59] SyntaxError: invalid 
syntax
[Tue Jun 04 19:50:16 2013] [error] [client 46.12.95.59] Premature end of script 
headers: files.py
[Tue Jun 04 19:50:16 2013] [error] [client 46.12.95.59] File does not exist: 
/home/nikos/public_html/500.shtml
-

What is the problem in your opinion Michael since verythign is encoded in utf-8?

why the cur.execute fail?
cur.execute('''SELECT url FROM files WHERE url = %s''', ( 
fullpath, )
data = cur.fetchone()#URL is unique, so should only be 
one
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Bools and explicitness [was Re: PyWart: The problem with "print"]

2013-06-04 Thread Chris Angelico
On Wed, Jun 5, 2013 at 2:19 AM, Rick Johnson
 wrote:
> On Jun 4, 11:00 am, Chris Angelico  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!

Option 1:

void C_function(int x)

Option 2:

def Python_function(x):
assert isinstance(x,int)

Is there a fundamental difference? You're basically proposing Option 2
while detesting Option 1.

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Bools and explicitness [was Re: PyWart: The problem with "print"]

2013-06-04 Thread Rick Johnson
On Jun 4, 11:00 am, Chris Angelico  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


Re: create new python file

2013-06-04 Thread Fábio Santos
On 4 Jun 2013 17:14,  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"]

2013-06-04 Thread Rick Johnson
On Jun 4, 10:44 am, Rick Johnson  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  and
   # var.length is greater than one.
   else:
   # if this block executes we know
   # that var is not of 
   # 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: Bools and explicitness [was Re: PyWart: The problem with "print"]

2013-06-04 Thread Fábio Santos
On 4 Jun 2013 17:04, "Chris Angelico"  wrote:
>
> On Wed, Jun 5, 2013 at 1:44 AM, Rick Johnson
>  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


create new python file

2013-06-04 Thread kakararunachalservice
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: lstrip problem - beginner question

2013-06-04 Thread mstagliamonte
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


Re: lstrip problem - beginner question

2013-06-04 Thread Mark Lawrence

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

2013-06-04 Thread John Gordon
In <1829efca-935d-4049-ba61-7138015a2...@googlegroups.com> mstagliamonte 
 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: Bools and explicitness [was Re: PyWart: The problem with "print"]

2013-06-04 Thread Chris Angelico
On Wed, Jun 5, 2013 at 1:44 AM, Rick Johnson
 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

2013-06-04 Thread mstagliamonte
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: lstrip problem - beginner question

2013-06-04 Thread Peter Otten
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

2013-06-04 Thread mstagliamonte
On Tuesday, June 4, 2013 11:41:43 AM UTC-4, Fábio Santos wrote:
> On 4 Jun 2013 16:34, "mstagliamonte"  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: Source code as text/plain

2013-06-04 Thread Andreas Perstinger

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


  1   2   >