[Tutor] os.getcwd() confusion

2013-05-20 Thread spangled spanner
G'day,

I have a comprehension issue here! I have made two simple scripts:

## script1

import os

print os.getcwd()

-
## script 2

import os

f = open('test', 'wb')
f.write(os.getcwd())
f.close()

_

Both scripts are in my home directory.
Using bash I cd to some other directory and call script 1:
 python ../../script1.py
and I get this result printed to the screen:
 users/scriptdir/dir1/dir2
i.e. the script returns the name of the directory that I'm currently
working in.

However if I call script2:
 python ../../script2.py
I get a result that to me seems inconsistent: the script writes the
directory
that IT is in (i.e., NOT the name of the directory I'm currently working
in),
to the file 'test' in the home directory.

I don't quite understand what is happening here! Any explanation would be
much appreciated.

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


Re: [Tutor] os.getcwd() confusion

2013-05-20 Thread Peter Otten
spangled spanner wrote:

 G'day,
 
 I have a comprehension issue here! I have made two simple scripts:
 
 ## script1
 
 import os
 
 print os.getcwd()
 
 -
 ## script 2
 
 import os
 
 f = open('test', 'wb')
 f.write(os.getcwd())
 f.close()
 
 _
 
 Both scripts are in my home directory.
 Using bash I cd to some other directory and call script 1:
 python ../../script1.py
 and I get this result printed to the screen:
 users/scriptdir/dir1/dir2
 i.e. the script returns the name of the directory that I'm currently
 working in.
 
 However if I call script2:
 python ../../script2.py
 I get a result that to me seems inconsistent: the script writes the
 directory
 that IT is in (i.e., NOT the name of the directory I'm currently working
 in),
 to the file 'test' in the home directory.
 
 I don't quite understand what is happening here! Any explanation would be
 much appreciated.

The test file will be written in the current working directory, too. You are 
looking into a leftover test file from a previous run.

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


[Tutor] Which version of python should i use?

2013-05-20 Thread Amal Thomas
hi,
   I am a beginner. I am using a unix sytem (ubuntu 12.10). Python 2.7.3
is installed in my system. I found out that Python has version upto 3.3.2.
Should I update my python version? Is the syntaxes of the each version
different?

Thanks,

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


Re: [Tutor] Retrieving data from a web site

2013-05-20 Thread Phil

On 20/05/13 17:55, Peter Otten wrote:


I've rerun the script and it still works over here. I'm in Germany, though,
and therefore there's a small chance that I'm being served different data.
What does

import urllib2



Thank you Peter for your detailed reply, I now have a better 
understanding of how json works.


I discovered my error just before receiving your reply. I'm a little 
embarrassed to admit that despite giving you the correct url I had 
attempted to get the results from another tatts page.


Thank you again, your help is greatly appreciated.

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


Re: [Tutor] Which version of python should i use?

2013-05-20 Thread Dave Angel

On 05/20/2013 05:59 AM, Amal Thomas wrote:

hi,
I am a beginner. I am using a unix sytem (ubuntu 12.10). Python 2.7.3
is installed in my system. I found out that Python has version upto 3.3.2.


Welcome, and thanks for telling us your environment up front.



Should I update my python version?


No.  Your OS has lots of dependencies on that installed Python, and if 
you remove that one (eg. replace it), many things will stop working.


HOWEVER, you can install a second Python, of whatever version, and use 
that for all your own experimenting and learning.  So the question is 
which one you should use for learning.  My comments at the end.



Is the syntaxes of the each version
different?



Yes.  Not only syntax but semantics as well.  Version 3.0 was 
deliberately a breaking update, where many of the painful gotchas in the 
language were fixed, even if it meant things were incompatible.  There 
is a 2to3 utility, but the transition can be painful for large programs.


Which one should you learn on?

#1 --- if you're committed to a particular tutorial, use the version 
that matches the tutorial.  At your stage, you don't want to have to 
convert every example in your head before getting it to work.


#2 --- If you have a particular library or libraries that you plan to 
use, and it's only currently available for one version, then use that 
version.


#3 --- If neither of the above apply, then use 3.3 or the soon-coming 3.4.

What's different?  For a beginner, the most noticeable different is that 
the print statement in 2.x was replaced by a print function in 3.x  For 
really simple cases, that just means slap a parentheses around the 
argument(s).  But the print statement has syntax for redirecting to a 
file, while the print function has a parameter.  And the technique for 
suppressing the trailing newline is different.  Etc.


The second most noticeable difference is that 3.x handles Unicode 
directly, so that a string is Unicode, and if you want bytes, those are 
different.





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


Re: [Tutor] Which version of python should i use?

2013-05-20 Thread eryksun
On Mon, May 20, 2013 at 5:59 AM, Amal Thomas amalthomas...@gmail.com wrote:
 I am a beginner. I am using a unix sytem (ubuntu 12.10). Python 2.7.3  is
 installed in my system. I found out that Python has version upto 3.3.2.
 Should I update my python version?

Ubuntu 12.10 should have 3.2.3 installed (the python3 package). The
command is python3. There's also a python3.3 package, currently at
version 3.30. The command is python3.3:

http://packages.ubuntu.com/quantal/python3
http://packages.ubuntu.com/quantal/python3.3
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Which version of python should i use?

2013-05-20 Thread Amal Thomas
Thank you very much..!! I am starting to learn python for my Bioinformatics
work, so I would look for the version that has libraries helpful for me..


On Mon, May 20, 2013 at 6:38 PM, Dave Angel da...@davea.name wrote:

 On 05/20/2013 05:59 AM, Amal Thomas wrote:

 hi,
 I am a beginner. I am using a unix sytem (ubuntu 12.10). Python 2.7.3
 is installed in my system. I found out that Python has version upto 3.3.2.


 Welcome, and thanks for telling us your environment up front.



  Should I update my python version?


 No.  Your OS has lots of dependencies on that installed Python, and if you
 remove that one (eg. replace it), many things will stop working.

 HOWEVER, you can install a second Python, of whatever version, and use
 that for all your own experimenting and learning.  So the question is which
 one you should use for learning.  My comments at the end.


  Is the syntaxes of the each version
 different?


 Yes.  Not only syntax but semantics as well.  Version 3.0 was deliberately
 a breaking update, where many of the painful gotchas in the language were
 fixed, even if it meant things were incompatible.  There is a 2to3 utility,
 but the transition can be painful for large programs.

 Which one should you learn on?

 #1 --- if you're committed to a particular tutorial, use the version that
 matches the tutorial.  At your stage, you don't want to have to convert
 every example in your head before getting it to work.

 #2 --- If you have a particular library or libraries that you plan to use,
 and it's only currently available for one version, then use that version.

 #3 --- If neither of the above apply, then use 3.3 or the soon-coming 3.4.

 What's different?  For a beginner, the most noticeable different is that
 the print statement in 2.x was replaced by a print function in 3.x  For
 really simple cases, that just means slap a parentheses around the
 argument(s).  But the print statement has syntax for redirecting to a file,
 while the print function has a parameter.  And the technique for
 suppressing the trailing newline is different.  Etc.

 The second most noticeable difference is that 3.x handles Unicode
 directly, so that a string is Unicode, and if you want bytes, those are
 different.




 --
 DaveA

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




-- 
*AMAL THOMAS
Third Year Undergraduate Student
Department of Biotechnology
IIT KHARAGPUR-721302*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Which version of python should i use?

2013-05-20 Thread Albert-Jan Roskam


On Mon, May 20, 2013 at 5:59 AM, Amal Thomas amalthomas...@gmail.com wrote:
 I am a beginner. I am using a unix sytem (ubuntu 12.10). Python 2.7.3  is
 installed in my system. I found out that Python has version upto 3.3.2.
 Should I update my python version?

Ubuntu 12.10 should have 3.2.3 installed (the python3 package). The
command is python3. There's also a python3.3 package, currently at
version 3.30. The command is python3.3:

Nice, I never knew that this was already installed. To what extent is Ubuntu (I 
use Mint, but I think that's almost the same) already using Python 3.2 
internally? I tried sudo updatedb; locate python3. But probably I should scan 
inside files to see where python3 is used. 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Which version of python should i use?

2013-05-20 Thread Steven D'Aprano

On 20/05/13 23:22, Albert-Jan Roskam wrote:


To what extent is Ubuntu (I use Mint, but I think that's almost the same) 
already using Python 3.2 internally?


Zero.

As far as I know, the only major Linux distro using Python 3 as the standard 
Python is Arch Linux, and they have a reputation for trail-blazing past the 
bleeding edge.


I tried sudo updatedb; locate python3.


That will only find files (or directories) with python3 in the name, not 
those that rely on Python3.


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


[Tutor] Random Number Game: Returns always the same number - why?

2013-05-20 Thread Rafael Knuth
Hello,

I wrote a simple program, and I was expecting that I would get 100
different random numbers. Instead, I am getting 100 times exactly the same
random number. Can anyone advise how I should alter my program?

Thank you!

All the best,

Rafael
PS. I am using Python 3.3.0

print (

This game will return 100 random numbers between 1 and 100.

)

import random

Count = 0

Random_Number = random.randint(1, 100)

while Count = 100:
print (Random_Number)

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


Re: [Tutor] Random Number Game: Returns always the same number - why?

2013-05-20 Thread boB Stepp
On Mon, May 20, 2013 at 11:31 AM, Rafael Knuth rafael.kn...@gmail.com wrote:

 Hello,

 I wrote a simple program, and I was expecting that I would get 100 different 
 random numbers. Instead, I am getting 100 times exactly the same random 
 number. Can anyone advise how I should alter my program?

 Thank you!

 All the best,

 Rafael
 PS. I am using Python 3.3.0

 print (

 This game will return 100 random numbers between 1 and 100.

 )

 import random

 Count = 0

 Random_Number = random.randint(1, 100)

 while Count = 100:
 print (Random_Number)

 Count = Count + 1

Your variable assignment for Random_Number is outside of your while
loop. Therefore its value never changes. Put it inside the while loop
just before the print statement and I think you will get what you
wanted.

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


Re: [Tutor] Random Number Game: Returns always the same number - why?

2013-05-20 Thread John R Jones
You need to move this line:

Random_Number = random.randint(1, 100)

into the loop body, like this:


while Count = 100:
 Random_Number = random.randint(1, 100)
 print (Random_Number)
 Count = Count + 1

 Hope this helps.



On Mon, May 20, 2013 at 9:31 AM, Rafael Knuth rafael.kn...@gmail.comwrote:

 Hello,

 I wrote a simple program, and I was expecting that I would get 100
 different random numbers. Instead, I am getting 100 times exactly the same
 random number. Can anyone advise how I should alter my program?

 Thank you!

 All the best,

 Rafael
 PS. I am using Python 3.3.0

 print (

 This game will return 100 random numbers between 1 and 100.

 )

 import random

 Count = 0

 Random_Number = random.randint(1, 100)

 while Count = 100:
 print (Random_Number)

 Count = Count + 1


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




-- 
John R Jones   n71...@gmail.com
10814 Des Moines Ave,  Porter Ranch, CA 91326
818-378-6206 cell/text,  310-531-8300 work, 424-234-9213 voicemail
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Random Number Game: Returns always the same number - why?

2013-05-20 Thread Mitya Sirenef

On 05/20/2013 12:31 PM, Rafael Knuth wrote:

Hello,


 I wrote a simple program, and I was expecting that I would get 100 
different random numbers. Instead, I am getting 100 times exactly the 
same random number. Can anyone advise how I should alter my program?


 Thank you!

 All the best,

 Rafael
 PS. I am using Python 3.3.0

 print (

 This game will return 100 random numbers between 1 and 100.

 )

 import random

 Count = 0

 Random_Number = random.randint(1, 100)

 while Count = 100:
 print (Random_Number)

 Count = Count + 1





There are a few issues here:
* variable names should be lower case
* for this case it's best to use for loop with range()
* you calculate random number only once, outside of loop

Try something like:

for count in range(100):
print random.randint(1, 100)


-m

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

“So many books, so little time.”
― Frank Zappa

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


Re: [Tutor] Beginner level: Why doesn't my code work?

2013-05-20 Thread Rafael Knuth
But this is all a distraction -- how exactly are you invoking what you think
is Python 3.3.0? What is your operating system?

My mistake, I am using two laptops with different operating systems
(Windows 7  SUSE 12.3). I am using Python 3.3.0 on the Windows laptop and
I was wrongly assuming that I am running the same version of Python on my
SUSE laptop. I simply forgot that I have a Python 2.x version on my SUSE
laptop. I tried that game on my Windows 7 laptop (where I have 3.3.0
installed) and it runs nicely.

Thank you for your support!

import random

print(

This is a magic super computer.

He will ask you a couple of questions.

An ultra-complicated algorithm will then figure out what your favorite meal
is.

)

name = input(What is your name? )

age = int(input(How old are you? ))

birthplace = input(Where are you born? )

meal = random.randint(1, 3)

if meal == 1:
print(Well,  + name +  as a  + str(age) +  year old human being
born in  + birthplace +  you probably like hamburgers.)

elif meal == 2:
print(Well,  + name +  as a  + str(age) +  year old human being
born in  + birthplace +  you probably like sushi.)

elif meal == 3:
print(Well,  + name +  as a  + str(age) +  year old human being
born in  + birthplace +  you probably like pizza.)


On Sun, May 19, 2013 at 4:54 PM, Peter Otten __pete...@web.de wrote:

 Rafael Knuth wrote:

  Thank you, I am using Python 3.3.0

 [Oscar]
  In Python 3 you should use input(). In Python 2 you should use
  raw_input(). I'm guessing that you're using Python 2. In Python 2 the
  input() function tries to evaluate whatever the user types in as if it
  was Python code. Since Rafael is not a defined variable it fails. The
  fix is to use raw_input() which just returns a string.


 [Rafael]
  I am not sure I understand.
  Rafael is the user's in put, and that value is assigned to the variable
  name.
  I made sure only a string is accepted as input
 
  name = (str(input(What's your name?))
 
  Can you clarify? Thank you in advance.

 As Oscar says you are invoking your script with Python 2. Python 2's
 input()
 function evals user input as a Python expression. For example if you run a
 script

 print input(your input please: )

 and you type

 1 + 1

 the script will print

 2

 Likewise if you type

 Rafael

 the script will look up the value of a variable named Rafael. This doesn't
 exist and therefore you get an exception.

 But this is all a distraction -- how exactly are you invoking what you
 think
 is Python 3.3.0? What is your operating system?

 If you are using Linux or OSX open a terminal window and try to run your
 script from that terminal window with

 python3.3 ~/Documents/3_Tufcik.py


 ___
 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


Re: [Tutor] Random Number Game: Returns always the same number - why?

2013-05-20 Thread Rafael Knuth
Your variable assignment for Random_Number is outside of your while
loop. Therefore its value never changes. Put it inside the while loop
just before the print statement and I think you will get what you

That was it! Thank you, you made my day, Bob :-)


On Mon, May 20, 2013 at 6:37 PM, boB Stepp robertvst...@gmail.com wrote:

 On Mon, May 20, 2013 at 11:31 AM, Rafael Knuth rafael.kn...@gmail.com
wrote:
 
  Hello,
 
  I wrote a simple program, and I was expecting that I would get 100
different random numbers. Instead, I am getting 100 times exactly the same
random number. Can anyone advise how I should alter my program?
 
  Thank you!
 
  All the best,
 
  Rafael
  PS. I am using Python 3.3.0
 
  print (
 
  This game will return 100 random numbers between 1 and 100.
 
  )
 
  import random
 
  Count = 0
 
  Random_Number = random.randint(1, 100)
 
  while Count = 100:
  print (Random_Number)
 
  Count = Count + 1
 
 Your variable assignment for Random_Number is outside of your while
 loop. Therefore its value never changes. Put it inside the while loop
 just before the print statement and I think you will get what you
 wanted.

 HTH,
 boB
 ___
 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


Re: [Tutor] Random Number Game: Returns always the same number - why?

2013-05-20 Thread Thomas Murphy
Mitya,
Why is it best in this situation to use range() rather than a while
loop? Curious about best practices for the various iterating
functions. Thanks!


 There are a few issues here:
 * variable names should be lower case
 * for this case it's best to use for loop with range()
 * you calculate random number only once, outside of loop

 Try something like:

 for count in range(100):
 print random.randint(1, 100)


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


Re: [Tutor] Random Number Game: Returns always the same number - why?

2013-05-20 Thread Mitya Sirenef

On 05/20/2013 12:55 PM, Thomas Murphy wrote:

Mitya,
Why is it best in this situation to use range() rather than a while
loop? Curious about best practices for the various iterating
functions. Thanks!



There are a few issues here:
* variable names should be lower case
* for this case it's best to use for loop with range()
* you calculate random number only once, outside of loop

Try something like:

for count in range(100):
print random.randint(1, 100)


-m


It's a simpler and more idiomatic approach, as you can
see, you don't need to initialize the counter and you don't
need to manually increment it.  -m


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

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


Re: [Tutor] Tutor Digest, Vol 111, Issue 68

2013-05-20 Thread Jim Mooney
   import random
  
   Count = 0
  
   Random_Number = random.randint(1, 100)
  
   while Count = 100:
   print (Random_Number)
  
   Count = Count + 1


 There are a few issues here:
 * variable names should be lower case
 * for this case it's best to use for loop with range()
 * you calculate random number only once, outside of loop

This gave rise to an interesting behavior, though. I ran it with
random outside the loop and indeed got the same number. Except the
number Changed right toward the end to one other number. I got a lot
of 19s, then a 17. The third time I got a lot of 23s, then a lot of
70s. This was consistent. Then I scrolled the results more slowly and
realized the program ran over 25,000 times and the anomalous numbers
were toward the end.

So why did it run about 25,000 times and why the change in number?

Here's the prog so you can see the loopvar count does increment so it
Should stop at 100.

import random

Count = 0
Random_Number = random.randint(1, 100)

Count = 0

while Count = 100:

print (Random_Number)
Count = Count + 1

I found the cause. If I just print Count it only goes to 100. If I
print Random_Number it goes to 25K. Is this consistent or a strange
flaw of Pyscripter?


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


[Tutor] reducing lists within list to their set of unique values

2013-05-20 Thread Treder, Robert
Hi python folks,
 
I have a list of lists that looks something like this: 
 
tst = [ [], ['test'], ['t1', 't2'], ['t1', 't1', 't2'] ]
 
I want to change the empty sets to a blank string, i.e., '' and the lists with 
repeat values to the unique set of values. So I have done the following: 
 
 for t in tst:
if len(t) == 0:
tst.__setitem__(tst.index(t), '')
else:
tst.__setitem__(tst.index(t), set(t))

What I get in return is 

 tst
['', set(['test']), set(['t2', 't1']), set(['t2', 't1'])]

The empty list is fine but the other lists seem to be expressions rather than 
values. What do I need to do to simply get the values back liike the following? 

['', ['test'], ['t2', 't1'], ['t2', 't1']]


Thanks, 
Bob
 





NOTICE: Morgan Stanley is not acting as a municipal advisor and the opinions or 
views contained herein are not intended to be, and do not constitute, advice 
within the meaning of Section 975 of the Dodd-Frank Wall Street Reform and 
Consumer Protection Act. If you have received this communication in error, 
please destroy all electronic and paper copies and notify the sender 
immediately. Mistransmission is not intended to waive confidentiality or 
privilege. Morgan Stanley reserves the right, to the extent permitted under 
applicable law, to monitor electronic communications. This message is subject 
to terms available at the following link: 
http://www.morganstanley.com/disclaimers. If you cannot access these links, 
please notify us by reply message and we will send the contents to you. By 
messaging with Morgan Stanley you consent to the foregoing.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] reducing lists within list to their set of unique values

2013-05-20 Thread Steven D'Aprano

On 21/05/13 08:49, Treder, Robert wrote:

Hi python folks,

I have a list of lists that looks something like this:

tst = [ [], ['test'], ['t1', 't2'], ['t1', 't1', 't2'] ]

I want to change the empty sets to a blank string, i.e., '' and the lists with 
repeat values to the unique set of values. So I have done the following:


for t in tst:

if len(t) == 0:
tst.__setitem__(tst.index(t), '')
else:
tst.__setitem__(tst.index(t), set(t))



As a general rule, if you are writing double-underscore special methods like __setitem__ 
directly, you're doing it wrong. (There are exceptions, but consider them for 
experts.)

So instead of tst.__setitem__(a, b) you should write tst[a] = b.

But that's still the wrong way to do this! You're doing a lot of extra work 
with the calls to tst.index. You won't notice for a short list like the example 
above, but for a long list, this will get really, really slow.

The way to do this is to keep track of the index as you walk over the list, and 
not recalculate it by searching the list:


for index, item in enumerate(tst):
if item == []:
item = 
else:
item = list(set(item))
tst[index] = item


Notice that I call set() to get the unique values, then list() again to turn it 
back into a list. This does the job you want, but it is not guaranteed to keep 
the order:

py L = ['b', 'd', 'c', 'a', 'b']
py list(set(L))
['a', 'c', 'b', 'd']


If keeping the order is important, you cannot use set, and you'll need another 
way to extract only the unique values. Ask if you need help on that.




What I get in return is


tst

['', set(['test']), set(['t2', 't1']), set(['t2', 't1'])]

The empty list is fine but the other lists seem to be expressions rather than 
values. What do I need to do to simply get the values back liike the following?

['', ['test'], ['t2', 't1'], ['t2', 't1']]



They are values. It is just that they are *sets* rather than *lists*. When 
printed, lists have a nice compact representation using square brackets [], but 
unfortunately sets do not. However, if you upgrade to Python 3, they have been 
upgraded to look a little nicer:


# Python 2:
set(['a', 'c', 'b', 'd'])

# Python 3
{'d', 'b', 'c', 'a'}


Notice that the order of the items is not guaranteed, but apart from that, the 
two versions are the same despite the difference in print representation.



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


[Tutor] still clarifying imorting

2013-05-20 Thread Jim Mooney
If I make a package called jimlib with __init__.py in it, and a
program called bark.py in it, and even put it in site packages, I
still have to import the program with   import jimlib.bark

But I noticed that the pygraphics package is in site packages, and has
media.py in it, and all I have to do with that is import media,
without qualifying it with pygraphics, as in import pygraphics.media

Why don't I have to drill down for media.py as I do with jimlib?

-- 
Jim Mooney

And as he walked along he carried some things in his small sack. Some
were useless and some were not. But the useless things he prized most
of all.  --The Story of Dirtville
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Random Number Game: Returns always the same number - why?

2013-05-20 Thread Amit Saha
Hi Rafael,


On Tue, May 21, 2013 at 2:51 AM, Rafael Knuth rafael.kn...@gmail.com wrote:

 Your variable assignment for Random_Number is outside of your while
 loop. Therefore its value never changes. Put it inside the while loop
 just before the print statement and I think you will get what you

 That was it! Thank you, you made my day, Bob :-)


Here is a visualization of how the lines of your original code are
executed: http://goo.gl/uRRTu.  Click on the Forward button there to
see the next line of code that is executed. You will see that in your
original code, the statement: Random_Number = random.randint(1, 100)
which actually generates your random numbers is executed only once.

Hope that helps your understanding.

Best,
Amit.

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


Re: [Tutor] Which version of python should i use?

2013-05-20 Thread Amit Saha
Hello Amal,

On Mon, May 20, 2013 at 11:24 PM, Amal Thomas amalthomas...@gmail.com wrote:
 Thank you very much..!! I am starting to learn python for my Bioinformatics
 work, so I would look for the version that has libraries helpful for me..

Do you already have any libraries in mind (or aware of) that  you
would want to use? I came across this link:
http://intro-prog-bioinfo-2012.wikispaces.com/, which doesn't seem to
use any specific tools other than the generic libraries that are
pretty much common in any scientific work involving Python: SciPy,
Numpy, etc.

The rule of thumb would probably be If you don't have any particular
library that you are looking to use and it doesn't yet support Python
3, then you may as well learn Python 3, since that is the future. I
think you may need to spend some time deciding this one. However that
said, why not start with Python 3? The programming language syntax and
style won't be different if you need to go by chance and use Python 2
at some other point of time.


Hope that helps.
-Amit.




 On Mon, May 20, 2013 at 6:38 PM, Dave Angel da...@davea.name wrote:

 On 05/20/2013 05:59 AM, Amal Thomas wrote:

 hi,
 I am a beginner. I am using a unix sytem (ubuntu 12.10). Python 2.7.3
 is installed in my system. I found out that Python has version upto
 3.3.2.


 Welcome, and thanks for telling us your environment up front.



 Should I update my python version?


 No.  Your OS has lots of dependencies on that installed Python, and if you
 remove that one (eg. replace it), many things will stop working.

 HOWEVER, you can install a second Python, of whatever version, and use
 that for all your own experimenting and learning.  So the question is which
 one you should use for learning.  My comments at the end.


 Is the syntaxes of the each version
 different?


 Yes.  Not only syntax but semantics as well.  Version 3.0 was deliberately
 a breaking update, where many of the painful gotchas in the language were
 fixed, even if it meant things were incompatible.  There is a 2to3 utility,
 but the transition can be painful for large programs.

 Which one should you learn on?

 #1 --- if you're committed to a particular tutorial, use the version that
 matches the tutorial.  At your stage, you don't want to have to convert
 every example in your head before getting it to work.

 #2 --- If you have a particular library or libraries that you plan to use,
 and it's only currently available for one version, then use that version.

 #3 --- If neither of the above apply, then use 3.3 or the soon-coming 3.4.

 What's different?  For a beginner, the most noticeable different is that
 the print statement in 2.x was replaced by a print function in 3.x  For
 really simple cases, that just means slap a parentheses around the
 argument(s).  But the print statement has syntax for redirecting to a file,
 while the print function has a parameter.  And the technique for suppressing
 the trailing newline is different.  Etc.

 The second most noticeable difference is that 3.x handles Unicode
 directly, so that a string is Unicode, and if you want bytes, those are
 different.




 --
 DaveA

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




 --
 AMAL THOMAS
 Third Year Undergraduate Student
 Department of Biotechnology
 IIT KHARAGPUR-721302

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




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


Re: [Tutor] still clarifying imorting

2013-05-20 Thread Dave Angel

On 05/20/2013 09:43 PM, Jim Mooney wrote:

If I make a package called jimlib with __init__.py in it, and a
program called bark.py in it, and even put it in site packages, I
still have to import the program with   import jimlib.bark

But I noticed that the pygraphics package is in site packages, and has
media.py in it, and all I have to do with that is import media,
without qualifying it with pygraphics, as in import pygraphics.media

Why don't I have to drill down for media.py as I do with jimlib?



I'd guess that pygraphics has some content in their __init__.py.  That 
content gets executed when you import it.


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


Re: [Tutor] still clarifying imorting

2013-05-20 Thread eryksun
On Mon, May 20, 2013 at 9:43 PM, Jim Mooney cybervigila...@gmail.com wrote:
 If I make a package called jimlib with __init__.py in it, and a
 program called bark.py in it, and even put it in site packages, I
 still have to import the program with   import jimlib.bark

 But I noticed that the pygraphics package is in site packages, and has
 media.py in it, and all I have to do with that is import media,
 without qualifying it with pygraphics, as in import pygraphics.media

 Why don't I have to drill down for media.py as I do with jimlib?

It's using a .pth file named pygraphics.pth, which should be in your
Lib\site-packages directory on NT. The first and only line is
pygraphics. This subdirectory is added to sys.path.

Specifically, in the setup.py for PyGraphics, it's using the
extra_path argument:

http://code.google.com/p/pygraphics/source/browse/trunk/setup.py#24

This argument is actually undocumented:

http://bugs.python.org/issue901727

To document this a bit, here's a snippet from the distutils source:

if len(self.extra_path) == 1:
path_file = extra_dirs = self.extra_path[0]
elif len(self.extra_path) == 2:
(path_file, extra_dirs) = self.extra_path
else:
raise DistutilsOptionError, \
  ('extra_path' option must be a list, tuple, or 
  comma-separated string with 1 or 2 elements)

And the function that creates the file:

def create_path_file (self):
filename = os.path.join(self.install_libbase,
self.path_file + .pth)
if self.install_path_file:
self.execute(write_file,
 (filename, [self.extra_dirs]),
 creating %s % filename)
else:
self.warn(path file '%s' not created % filename)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor