Re: [Tutor] Converting from a single module to a package

2011-08-06 Thread Timo

On 06-08-11 01:38, Emile van Sebille wrote:

On 8/5/2011 4:22 PM Tim Johnson said...

* Christopher King  [110805 12:03]:

To make a package, you make a folder named what you want to name the
package, for example: virus_toolkit. Then you make a file in it called
__init__.py. This is what you import if you import the 
virus_toolkit. You

usually put documentation and general functions in this



But you can provide for both methods if in tlib.__init__ you provide 
for backward compatibility.




  # current way
  import tlib as std
  
  std.htmlButton(*arglist)

  # New way, after transition
  import tlib as std


in tlib.__init__, include the following:

import html
htmlButton = html.button
And print a deprecation warning when people use it like this. That way 
you let them know this method could be removed in a next version.

See the warnings module.

Cheers,
Timo




  std.html.button(*arglist)
  #OR
  import html from tlib
  html.button(*arglist)


Emile

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] adding dictionary value at position [-1]

2011-08-06 Thread Norman Khine
hello,
i know that there are no indexes/positions in a python dictionary,
what will be the most appropriate way to do this:

addresses = {}
for result in results.get_documents():
addresses[result.name] = result.title
# we add a create new address option, this needs to be
the last value
addresses['create-new-address'] = 'Create new address!'

   # {"address-one": "Address One", "create-new-address":
"Create new address!", "address-two": "Address Two"}

return dumps(addresses)


so that when i return the 'dumps(addresses)', i would like the
'create-new-address' to be always at the last position.

any advise much appreciated.

norman

-- 
˙ʇı ɹoɟ ƃuıʎɐd ǝɹ,noʎ ʍou puɐ ǝɔıoɥɔ ɐ ʞooʇ ı ʇɐɥʇ sı 'ʇlnɔıɟɟıp sı ʇɐɥʍ
˙uʍop ǝpısdn p,uɹnʇ pןɹoʍ ǝɥʇ ǝǝs noʎ 'ʇuǝɯɐן sǝɯıʇ ǝɥʇ puɐ 'ʇuǝʇuoɔ
ǝq s,ʇǝן ʇǝʎ
%>>> "".join( [ {'*':'@','^':'.'}.get(c,None) or
chr(97+(ord(c)-83)%26) for c in ",adym,*)&uzq^zqf" ] )
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] adding dictionary value at position [-1]

2011-08-06 Thread Rafael Durán Castañeda
Resending to list, since I click reply instead of reply to list, I'm 
sorry Norman since you are receiving twice:


If you need an order item, use a list, so you can use a dictionary 
containing an ordered list of dictionaries. I think you want do somthing 
like this:


import json
addresses = {}
addresses['values'] = []
values = [1, 2, 3]

for index,value in enumerate(values):
addresses['values'].append({index: value})

print(json.dumps(addresses))

Output will be:

{"values": [{"0": 1}, {"1": 2}, {"2": 3}]}

On 06/08/11 13:32, Norman Khine wrote:

hello,
i know that there are no indexes/positions in a python dictionary,
what will be the most appropriate way to do this:

 addresses = {}
 for result in results.get_documents():
 addresses[result.name] = result.title
 # we add a create new address option, this needs to be
the last value
 addresses['create-new-address'] = 'Create new address!'

# {"address-one": "Address One", "create-new-address":
"Create new address!", "address-two": "Address Two"}

 return dumps(addresses)


so that when i return the 'dumps(addresses)', i would like the
'create-new-address' to be always at the last position.

any advise much appreciated.

norman



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] adding dictionary value at position [-1]

2011-08-06 Thread Dave Angel

On 08/06/2011 07:32 AM, Norman Khine wrote:

hello,
i know that there are no indexes/positions in a python dictionary,
what will be the most appropriate way to do this:

 addresses = {}
 for result in results.get_documents():
 addresses[result.name] = result.title
 # we add a create new address option, this needs to be
the last value
 addresses['create-new-address'] = 'Create new address!'

# {"address-one": "Address One", "create-new-address":
"Create new address!", "address-two": "Address Two"}

 return dumps(addresses)


so that when i return the 'dumps(addresses)', i would like the
'create-new-address' to be always at the last position.

any advise much appreciated.

norman


We can assume this is a fragment of a function, since it ends with a return.

You don't say what this function is supposed to return, and you don't 
supply the source for dumps().


So, applying my crystal ball and figuring you want a list, just write 
dumps so it puts the create-new-address entry at the end.  You could 
ensure that by changing the name create-new-address to 
zzz-create-new-address, and simply doing a sort.  Or you could simply return

   return dumps(addresses) + "Create new address"

and not put it into the dictionary at all.
--

DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] adding dictionary value at position [-1]

2011-08-06 Thread Norman Khine
hello, thanks for the replies

On Sat, Aug 6, 2011 at 2:07 PM, Dave Angel  wrote:
> On 08/06/2011 07:32 AM, Norman Khine wrote:
>>
>> hello,
>> i know that there are no indexes/positions in a python dictionary,
>> what will be the most appropriate way to do this:
>>
>>                 addresses = {}
>>                 for result in results.get_documents():
>>                     addresses[result.name] = result.title
>>                 # we add a create new address option, this needs to be
>> the last value
>>                 addresses['create-new-address'] = 'Create new address!'
>>
>>                # {"address-one": "Address One", "create-new-address":
>> "Create new address!", "address-two": "Address Two"}
>>
>>                 return dumps(addresses)
>>
>>
>> so that when i return the 'dumps(addresses)', i would like the
>> 'create-new-address' to be always at the last position.
>>
>> any advise much appreciated.
>>
>> norman
>>
> We can assume this is a fragment of a function, since it ends with a return.
>
> You don't say what this function is supposed to return, and you don't supply
> the source for dumps().

the function returns:

{"address-one": "Address One", "create-new-address": "Create new
address!", "zzz-address-two": "ZZZ Address Two"}

>
> So, applying my crystal ball and figuring you want a list, just write dumps
> so it puts the create-new-address entry at the end.  You could ensure that
> by changing the name create-new-address to zzz-create-new-address, and
> simply doing a sort.  Or you could simply return
>   return dumps(addresses) + "Create new address"
>
> and not put it into the dictionary at all.
> --
>
> DaveA
>
>



-- 
˙ʇı ɹoɟ ƃuıʎɐd ǝɹ,noʎ ʍou puɐ ǝɔıoɥɔ ɐ ʞooʇ ı ʇɐɥʇ sı 'ʇlnɔıɟɟıp sı ʇɐɥʍ
˙uʍop ǝpısdn p,uɹnʇ pןɹoʍ ǝɥʇ ǝǝs noʎ 'ʇuǝɯɐן sǝɯıʇ ǝɥʇ puɐ 'ʇuǝʇuoɔ
ǝq s,ʇǝן ʇǝʎ
%>>> "".join( [ {'*':'@','^':'.'}.get(c,None) or
chr(97+(ord(c)-83)%26) for c in ",adym,*)&uzq^zqf" ] )
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Basic web form interaction with http://propka.ki.ku.dk/

2011-08-06 Thread Troels Emtekær Linnet
Dear Python users.

I am an semi-experienced in python, but totally new on the web interactions.
I have been working with scripts to the protein program Pymol, which can be
extended with python script.

I hope that some of you can help me with an interaction script to
http://propka.ki.ku.dk/.
I hope that some of you can show be a basic python script to load the
suitable python modules and interacting
with the web form.

The main idea is, to load a protein structure in pymol.
Then writing a pymol/python script that saves the stucture of the protein
into a .pdb file.
Then open http://propka.ki.ku.dk/, send the .pdb file, wait 1-2 minutes for
the result, and capture the result.

I hope that some of you can show be the basics steps, to interact with the
web form.

Best
Troels
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Basic web form interaction with http://propka.ki.ku.dk/

2011-08-06 Thread Mateusz Koryciński
Hi,

Have You tried something similar to interface used in BioPython? I think U
could get solution by reading code for connection with databases like
Entrez. Maybe this will give you some ideas.

Do you want your script to download pdb file from PDB database? Or you want
only sending and receiving from propka?


Cheers,
Mateusz

2011/8/6 Troels Emtekær Linnet 

> Dear Python users.
>
> I am an semi-experienced in python, but totally new on the web
> interactions.
> I have been working with scripts o the protein program Pymol, which can be
> extended with python script.
>
> I hope that some of you can help me with an interaction script to
> http://propka.ki.ku.dk/.
> I hope that some of you can show be a basic python script to load the
> suitable python modules and interacting
> with the web form.
>
> The main idea is, to load a protein structure in pymol.
> Then writing a pymol/python script that saves the stucture of the protein
> into a .pdb file.
> Then open http://propka.ki.ku.dk/, send the .pdb file, wait 1-2 minutes
> for the result, and capture the result.
>
> I hope that some of you can show be the basics steps, to interact with the
> web form.
>
> Best
> Troels
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>


-- 
Pozdrawiam,
Mateusz Koryciński
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Basic web form interaction with http://propka.ki.ku.dk/

2011-08-06 Thread Troels Emtekær Linnet
Hi Mateus.

No, I was certainly not aware of BioPython. What a nice project. I will
check it out.

No, the script should not download a .pdb file.
The idea is, that a "researcher/student" sits with his/hers favorite protein
in pymol and would like to know the pKa value
of his/hers favorite amino acids.

The student "probably" has only pymol installed, and would not like to
install to many other python packages.
Maybe the student can't, because it is a university computer.

With this web-interaction script, the students activate the script, with:
get_pka Molecule, residue

The script saves the molecule to a .pdb file. Interact with the propka web
site, send the file, wait 1 minute, grep for the line
with the amino acid, and parse it back to pymol, so the student can see the
pKa.

To big benefit with this, is that the student does not have to handle to
hard installations of scripts/programs or the manual way.
And the student knows, that the pKa prediction is from the newest software
available.
If the student get greedy, he/she starts writing a pymol script that alter
the pdb structure in pymol, and receive the new pKa value for each
structural change.
The downside, is of course the "waiting" time for the server response.

Best
Troels



Troels Emtekær Linnet
Karl-Liebknecht-Straße 53, 2 RE 
04107 Leipzig, Tyskland
Mobil: +49 1577-8944752



2011/8/6 Mateusz Koryciński 

> Hi,
>
> Have You tried something similar to interface used in BioPython? I think U
> could get solution by reading code for connection with databases like
> Entrez. Maybe this will give you some ideas.
>
> Do you want your script to download pdb file from PDB database? Or you want
> only sending and receiving from propka?
>
>
> Cheers,
> Mateusz
>
> 2011/8/6 Troels Emtekær Linnet 
>
>> Dear Python users.
>>
>> I am an semi-experienced in python, but totally new on the web
>> interactions.
>> I have been working with scripts o the protein program Pymol, which can be
>> extended with python script.
>>
>>
>> I hope that some of you can help me with an interaction script to
>> http://propka.ki.ku.dk/.
>> I hope that some of you can show be a basic python script to load the
>> suitable python modules and interacting
>> with the web form.
>>
>> The main idea is, to load a protein structure in pymol.
>> Then writing a pymol/python script that saves the stucture of the protein
>> into a .pdb file.
>> Then open http://propka.ki.ku.dk/, send the .pdb file, wait 1-2 minutes
>> for the result, and capture the result.
>>
>> I hope that some of you can show be the basics steps, to interact with the
>> web form.
>>
>> Best
>> Troels
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>
>
> --
> Pozdrawiam,
> Mateusz Koryciński
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Basic web form interaction with http://propka.ki.ku.dk/

2011-08-06 Thread Mateusz Koryciński
Hi,

IMHO, first of all you should check if server admins allow automatic
connection outside web browser. Maybe they do and there a simple way to
connect and they will tell you how (for example how query should look like
as a command for software installed on server). I just check and they have
link to source code and some scripts - check this out, maybe there are
scripts for sending query?

About libraries - I don't really know how it looks like in Windows, but in
Linux (I am working mostly with it) you can download libraries to home
folder and import them to script directly from directory. Or you can export
new path to show python where it should look for libraries. In this case you
don't need root privileges.

If it's bioinformatics classes you should ask department admin to install
biopython. It have libraries to handle pdb files so it could be very
helpful.

Cheers,
Mateusz

2011/8/6 Troels Emtekær Linnet 

> Hi Mateus.
>
> No, I was certainly not aware of BioPython. What a nice project. I will
> check it out.
>
> No, the script should not download a .pdb file.
> The idea is, that a "researcher/student" sits with his/hers favorite
> protein in pymol and would like to know the pKa value
> of his/hers favorite amino acids.
>
> The student "probably" has only pymol installed, and would not like to
> install to many other python packages.
> Maybe the student can't, because it is a university computer.
>
> With this web-interaction script, the students activate the script, with:
> get_pka Molecule, residue
>
> The script saves the molecule to a .pdb file. Interact with the propka web
> site, send the file, wait 1 minute, grep for the line
> with the amino acid, and parse it back to pymol, so the student can see the
> pKa.
>
> To big benefit with this, is that the student does not have to handle to
> hard installations of scripts/programs or the manual way.
> And the student knows, that the pKa prediction is from the newest software
> available.
> If the student get greedy, he/she starts writing a pymol script that alter
> the pdb structure in pymol, and receive the new pKa value for each
> structural change.
> The downside, is of course the "waiting" time for the server response.
>
> Best
> Troels
>
>
>
> Troels Emtekær Linnet
> Karl-Liebknecht-Straße 53, 2 RE 
> 04107 Leipzig, Tyskland
> Mobil: +49 1577-8944752
>
>
>
> 2011/8/6 Mateusz Koryciński 
>
>> Hi,
>>
>> Have You tried something similar to interface used in BioPython? I think U
>> could get solution by reading code for connection with databases like
>> Entrez. Maybe this will give you some ideas.
>>
>> Do you want your script to download pdb file from PDB database? Or you
>> want only sending and receiving from propka?
>>
>>
>> Cheers,
>> Mateusz
>>
>> 2011/8/6 Troels Emtekær Linnet 
>>
>>> Dear Python users.
>>>
>>> I am an semi-experienced in python, but totally new on the web
>>> interactions.
>>> I have been working with scripts o the protein program Pymol, which can
>>> be extended with python script.
>>>
>>>
>>> I hope that some of you can help me with an interaction script to
>>> http://propka.ki.ku.dk/.
>>> I hope that some of you can show be a basic python script to load the
>>> suitable python modules and interacting
>>> with the web form.
>>>
>>> The main idea is, to load a protein structure in pymol.
>>> Then writing a pymol/python script that saves the stucture of the protein
>>> into a .pdb file.
>>> Then open http://propka.ki.ku.dk/, send the .pdb file, wait 1-2 minutes
>>> for the result, and capture the result.
>>>
>>> I hope that some of you can show be the basics steps, to interact with
>>> the web form.
>>>
>>> Best
>>> Troels
>>>
>>> ___
>>> Tutor maillist  -  Tutor@python.org
>>> To unsubscribe or change subscription options:
>>> http://mail.python.org/mailman/listinfo/tutor
>>>
>>>
>>
>>
>> --
>> Pozdrawiam,
>> Mateusz Koryciński
>>
>
>


-- 
Pozdrawiam,
Mateusz Koryciński
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] adding dictionary value at position [-1]

2011-08-06 Thread Alan Gauld

On 06/08/11 12:32, Norman Khine wrote:

hello,
i know that there are no indexes/positions in a python dictionary,
what will be the most appropriate way to do this:

 addresses = {}
 for result in results.get_documents():
 addresses[result.name] = result.title
 addresses['create-new-address'] = 'Create new address!'
 return dumps(addresses)

so that when i return the 'dumps(addresses)', i would like the
'create-new-address' to be always at the last position.


Translating that into English, what I think you want is:

You want to print a dictionary (or return a string representation?) such 
that the last thing added to the dictionary is the last thing listed? 
Or, do you want the string representation to have all of the items in 
the order they were inserted?


Or do you want the string representation to always have the specific 
'create_new_address' listed last regardless of where it was originally 
inserted?


And do you really want just a string representation in this order or do 
you really want the data stored and accessible in that order? (In which 
case don't use a dictionary!)


I guess the real question is why you need the dictionary in the first 
place? Dictionaries facilitate random access to your data based on key 
values. Is that a necessary feature of your application? If so use a 
dictionary but consider adding an index value to the data(*). You can 
then sort the dictionary based on that index. If you don;t need the 
random access aspect then store the data in a list of (key,value) tuples 
instead.


(*)One way to add an index is:

def insert_in_dict(d,key,val):
d[key] = (len(d), val)

Obviously you need to drop the index when accessing the real values:

def get_real_val(d,key):
return d[key][1]

And you could even clean all that up by creating a class derived from dict.

You can then sort the dictionary by providing a key function to extract 
the index to sorted()



HTH

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] adding dictionary value at position [-1]

2011-08-06 Thread Peter Otten
Alan Gauld wrote:

> On 06/08/11 12:32, Norman Khine wrote:
>> hello,
>> i know that there are no indexes/positions in a python dictionary,
>> what will be the most appropriate way to do this:
>>
>>  addresses = {}
>>  for result in results.get_documents():
>>  addresses[result.name] = result.title
>>  addresses['create-new-address'] = 'Create new address!'
>>  return dumps(addresses)
>>
>> so that when i return the 'dumps(addresses)', i would like the
>> 'create-new-address' to be always at the last position.
> 
> Translating that into English, what I think you want is:
> 
> You want to print a dictionary (or return a string representation?) such
> that the last thing added to the dictionary is the last thing listed?
> Or, do you want the string representation to have all of the items in
> the order they were inserted?
> 
> Or do you want the string representation to always have the specific
> 'create_new_address' listed last regardless of where it was originally
> inserted?
> 
> And do you really want just a string representation in this order or do
> you really want the data stored and accessible in that order? (In which
> case don't use a dictionary!)
> 
> I guess the real question is why you need the dictionary in the first
> place? Dictionaries facilitate random access to your data based on key
> values. Is that a necessary feature of your application? If so use a
> dictionary but consider adding an index value to the data(*). You can
> then sort the dictionary based on that index. If you don;t need the
> random access aspect then store the data in a list of (key,value) tuples
> instead.
> 
> (*)One way to add an index is:
> 
> def insert_in_dict(d,key,val):
>  d[key] = (len(d), val)
> 
> Obviously you need to drop the index when accessing the real values:
> 
> def get_real_val(d,key):
>  return d[key][1]
> 
> And you could even clean all that up by creating a class derived from
> dict.

In Python 2.7 there is already such a class: collections.OrderedDict:

>>> from collections import OrderedDict
>>> up = OrderedDict.fromkeys("abc")
>>> down = OrderedDict.fromkeys("cba")
>>> up
OrderedDict([('a', None), ('b', None), ('c', None)])
>>> down
OrderedDict([('c', None), ('b', None), ('a', None)])


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [Python-ideas] Access to function objects

2011-08-06 Thread Christopher King
On Sat, Aug 6, 2011 at 4:10 AM, David Townshend wrote:
>
> def counter(add) as func:
> if not hasattr(func, 'count'):
> func.count = 0
> func.count += 1
> print(func.count)
>
You already can do that without an as statment.

>>> def counter(add):
if not hasattr(counter, 'count'):
counter.count = 0
counter.count += 1
return counter.count
>>> counter('You ever notice how this parameter is never used anyway?')
Output: 1
>>> counter('Oh well')
Output: 2
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] gzip

2011-08-06 Thread questions anon
Hi All,
I am trying to decompress at gzipped netcdf file and place the decompressed
file in the same folder without the *.gz extension. I am using gzip. If I
use the following code nothing happens.

import gzip
filepath="D:/test/surfacetemp.nc.gz"
compresseddata=gzip.open(filepath, "rb")
file_content=compresseddata.read()

How can I output the decompressed file? something like:
output=file_content.write(filepath[:-3])

thanks
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] gzip

2011-08-06 Thread Walter Prins
On 7 August 2011 01:52, questions anon  wrote:

> How can I output the decompressed file? something like:
> output=file_content.write(filepath[:-3])
>
>
See here:
http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-files
And here:
http://docs.python.org/library/stdtypes.html#file.write

Walter
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] commandline unable to read numbers?

2011-08-06 Thread Robert Sjoblom
I have a quite odd problem, and I've come across it before but
probably ignored it at the time because I had other concerns. I've
tried googling for the answer but haven't really come closer to
solving it.
This is what happens:
C:\[path]\nester>C:\Python32\python.ex
e setup.py register
running register
running check
We need to know who you are, so please choose either:
 1. use your existing login,
 2. register as a new user,
 3. have the server generate a new password for you (and email it to you), or
 4. quit
Your selection [default 1]:
1
Please choose one of the four options!
We need to know who you are, so please choose either:
 1. use your existing login,
 2. register as a new user,
 3. have the server generate a new password for you (and email it to you), or
 4. quit
Your selection [default 1]:

No matter what I enter it will loop back. It seems my commandline
can't read numbers? The other time I noticed it was while working on a
notebook example:

class Menu:
"""Display a menu and respond to choices when run."""
def __init__(self):
self.notebook = Notebook()
self.choices = {
"1": self.show_notes,
"2": self.search_notes,
"3": self.add_note,
"4": self.modify_note,
"5": self.quit
}

def display_menu(self):
print("""
Notebook Menu

1. Show All Notes
2. Search Notes
3. Add Note
4. Modify Note
5. Quit
""")

def run(self):
"""Display the menu and respond to choices."""
while True:
self.display_menu()
choice = input("Enter an option: ")
action = self.choices.get(choice)
if action:
action()
else:
print("{0} is not a valid choice.".format(choice))

This code works in IDLE, so I know it's nothing in the actual code
that's a problem, but when I run it in commandline it will just repeat
"is not a valid choice." Note that it does this no matter what I
actually enter, it won't actually get any kind of input except the
enter key. So I suppose it's a problem with input() (I'm using python
3.2 btw). Anyone have any insights?
-- 
best regards,
Robert S.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] commandline unable to read numbers?

2011-08-06 Thread Steven D'Aprano

Robert Sjoblom wrote:

I have a quite odd problem, and I've come across it before but
probably ignored it at the time because I had other concerns. I've
tried googling for the answer but haven't really come closer to
solving it.
This is what happens:
C:\[path]\nester>C:\Python32\python.ex
e setup.py register
running register
running check
We need to know who you are, so please choose either:
 1. use your existing login,
 2. register as a new user,
 3. have the server generate a new password for you (and email it to you), or
 4. quit
Your selection [default 1]:
1
Please choose one of the four options!


Looks like a bug in the setup.py script. You should report it to the 
author of the package.


Have you tried just pressing enter without entering anything?



No matter what I enter it will loop back. It seems my commandline
can't read numbers? The other time I noticed it was while working on a
notebook example:

[...]

This code works in IDLE, so I know it's nothing in the actual code
that's a problem, 


Apart from the fact that it is incomplete and won't run as given, it 
seems fine.




but when I run it in commandline it will just repeat
"is not a valid choice." Note that it does this no matter what I
actually enter, it won't actually get any kind of input except the
enter key. So I suppose it's a problem with input() (I'm using python
3.2 btw). Anyone have any insights?


You're not telling us how you're running it from the command line. My 
guess is that when you try, you're ending up with a different version of 
Python, namely Python 2.x, where input() has different semantics.


Try putting

print("choice = ", choice, type(choice))

immediately after the call to input in your code, and seeing what it 
prints. My guess is that it will claim choice is a int instead of a string.



--
Steven

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor