Re: [Tutor] user created lists

2012-04-11 Thread Christian Witts

On 2012/04/12 06:42 AM, john moore wrote:

Hello Pyhton World,

I'm new at this and was wondering how I create a number of user specified lists?

Example:

"How many list would you like to create?"
User inputs 5
creates five lists,
list1 []
list2 []
list3 []
list4 []
list5 []

I can create one with append, but I don't know how to loop it to create five 
different named list..
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


You can use vars() to create the variables on the fly. vars() is just a 
dictionary containing the variable name as the key, and the data as the 
value so you can do `vars()['list1'] = []` and it's easy enough to 
create them en masse


# Set the start to 1, and add 1 to what the user inputted
# as range/xrange doesn't include the top number
for i in xrange(1, user_input + 1):
vars()['list%s' % i] = []

Hope that helps.
--

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


Re: [Tutor] write list to columns

2012-04-11 Thread questions anon
Perfect, thank you.
Is there a way I could easily/quickly add headings to each column?

On Thu, Apr 12, 2012 at 1:03 PM, Puneeth Chaganti wrote:

> On Thu, Apr 12, 2012 at 8:01 AM, questions anon
>  wrote:
> > I am trying to simply write a list of values to txt file in one column.
> > I would then like to add another list in a second column.
> > Somehow they only appear as one long row.
> > Any feedback will be greatly appreciated.
>
> You will need to write each line of the file separately, with the
> formatting you desire for each line.
> The following example may help.
>
>
> A = range(5)
> B = range(5, 10)
>
> records = zip(A, B)
> output_format = '%s %s'
>
> with open('output.txt', 'w') as f:
>for record in records:
>f.write(output_format %(record))
>f.write('\n')
>
>
> HTH,
> Puneeth
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] user created lists

2012-04-11 Thread john moore
Hello Pyhton World,

I'm new at this and was wondering how I create a number of user specified lists?

Example:

"How many list would you like to create?"
User inputs 5
creates five lists,
list1 []
list2 []
list3 []
list4 []
list5 []

I can create one with append, but I don't know how to loop it to create five 
different named list.. 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] write list to columns

2012-04-11 Thread Puneeth Chaganti
On Thu, Apr 12, 2012 at 8:01 AM, questions anon
 wrote:
> I am trying to simply write a list of values to txt file in one column.
> I would then like to add another list in a second column.
> Somehow they only appear as one long row.
> Any feedback will be greatly appreciated.

You will need to write each line of the file separately, with the
formatting you desire for each line.
The following example may help.


A = range(5)
B = range(5, 10)

records = zip(A, B)
output_format = '%s %s'

with open('output.txt', 'w') as f:
for record in records:
f.write(output_format %(record))
f.write('\n')


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


Re: [Tutor] write list to columns

2012-04-11 Thread शंतनू

On 12-Apr-2012, at 8:01 AM, questions anon wrote:

> I am trying to simply write a list of values to txt file in one column.
> I would then like to add another list in a second column.
> Somehow they only appear as one long row. 
> Any feedback will be greatly appreciated. 
> 
> print "rain max values", rmax
> print "yearmonth", month year

'print' adds newline automatically.
More info:
http://docs.python.org/reference/simple_stmts.html#print

> OutputFolder=r"E:/test_out/"
> myfile=open(OutputFolder+'test.txt','w')
> myfile.write(str(monthyear))
> myfile.write(str(rmax))
> myfile.close()

'write' does not add newline. You need to add '\n' where you want new line.


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


[Tutor] write list to columns

2012-04-11 Thread questions anon
I am trying to simply write a list of values to txt file in one column.
I would then like to add another list in a second column.
Somehow they only appear as one long row.
Any feedback will be greatly appreciated.

print "rain max values", rmax
print "yearmonth", monthyear

OutputFolder=r"E:/test_out/"
myfile=open(OutputFolder+'test.txt','w')
myfile.write(str(monthyear))
myfile.write(str(rmax))
myfile.close()

In python:
rain max values [43.8748, 35.8382701, 18.6598499,
60.2017099, 21.69989, 25.27929, 16.0810099,
14.1987299, 33.5246, 19.7101702, 22.9042099,
17.3019299, 39.3724102, 39.2906403,
25.4428201, 33.3223397, 28.2529701,
40.3887199, 8.76276001, 54.5164602, 109.756,
15.8635199, 31.5986001]
yearmonth ['20110906', '20110907', '20110908', '20110909', '20110910',
'20110911', '20110912', '20110913', '20110914', '20110915', '20110916',
'20110917', '20110918', '20110919', '20110920', '20110921', '20110922',
'20110923', '20110924', '20110925', '20110926', '20110927', '20110928']

in my text file:
['20110906', '20110907', '20110908', '20110909', '20110910', '20110911',
'20110912', '20110913', '20110914', '20110915', '20110916', '20110917',
'20110918', '20110919', '20110920', '20110921', '20110922', '20110923',
'20110924', '20110925', '20110926', '20110927', '20110928'][43.8748,
35.8382701, 18.6598499, 60.2017099, 21.69989,
25.27929, 16.0810099, 14.1987299, 33.5246,
19.7101702, 22.9042099, 17.3019299,
39.3724102, 39.2906403, 25.4428201,
33.3223397, 28.2529701, 40.3887199,
8.76276001, 54.5164602, 109.756, 15.8635199,
31.5986001]
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python connect() function

2012-04-11 Thread Walter Prins
Hi Pierre,

On 11 April 2012 15:49, Pierre Barthelemy  wrote:

> I have a question about event handling and the use of the connect
> function. I have a data object, that contains a series of signals, one
> being "new_data_point" .


Where does this "connect function" come from and how does it work?  Did you
write it or is it part of some framework/third party software?  Suffice it
to say there is no standard "connect function" in plain Python itself that
has to do with signals and event driven programming, so you really need to
tell us a bit more about what frameworks etc you're using and what you're
doing, otherwise we can't try to help you effectively.

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


Re: [Tutor] how to build a multiplayer game?

2012-04-11 Thread Alan Gauld

On 11/04/12 14:30, Surya K wrote:


Don't you think DNS is required as IP addr may be same for some people
in this world.. after all, we only have limited number of combinations.


DNS only translates a names IP address into a numeric IP address. It 
does not create any extra addresses - thats why we are running out of IP 
numbers!


You may be thinking of NAT which translates a public IP address into
a local network address and thus allows many computers to share the same 
set of private IP addrewsses - 198.162,x.y for example can be
used on any LAN and the LAN will be seen from the outside as another 
public IP address.


But all of that would be handled by whatever network configuration you 
and your users have set up. The only exception might be that to get 
through a firewall you need to open up a particular port number.



* I even got a wild idea, can't we use a IRC channel, create a group and
we make sure that each user of the game will be a member of the group??
approx, how much delay would be there??


Yes thats a possibility too. But then you will need an IRC server 
somewhere. Setting up an IRC server is not much different from

setting up a web app server.

Delay on the internet is highly dependant on routing. If your packet 
happens to go the wrong way it can wind up jumping around all manner of 
very busy/slow networks before it reaches you, in which case it might 
take a few seconds to reach you. OTOH it might rout via a direct link 
betwen the two ISPs involved and the delay will be <=100ms...


Part of the challenge of network programming is deciding how to deal 
with those two scenarios. It's perfectly possible for packets to arrive 
out of sync (ie packet two arrives before packet 1 because they were 
routed differently). Do you hold packet 2 and wait for the late packet 
or request a resend as soon as packet 2 arrives? There are no right or 
wrong answers, just different choices for a given scenario.


--
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] how to build a multiplayer game?

2012-04-11 Thread Alan Gauld

On 11/04/12 11:02, Surya K wrote:

I have written the basic part of the game. Now I want to make it a
multiplayer one. (Its not a web app, a OS application)

So, I just wanted to know how do it.

Which topics I should refer? Network Programming or Web Programming or
Internet Client Programming.


That all depends on how you decide to build the game. And what kind of 
interaction you need. The fastest most direct route is to use raw peer 
to peer sockets and send string messages between the two computers.
But then you need to decide how to set up the connection, who is master 
anmd who is slave per session etc. A lot less work if you adopt the web 
model of an app server in the middle and both players connect to that.


For straight sockets you should find examples in Wes' book.
Or you can read the network programming topic in my tutorial.

--
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] how to build a multiplayer game?

2012-04-11 Thread Chris Fuller

I think you're on the right track with the IRC idea, but start with something 
simpler.  You can find tutorials or working programs using the asynchat module 
to make a really basic chat client.  Then you build a higher level protocol on 
top of that.  It should take care of most of the low level networking for you.  
But when you're ready for that, look up nonblocking I/O and the select() 
system call.

http://pypi.python.org/
http://code.activestate.com/recipes/langs/python/
http://docs.python.org/howto/sockets.html#non-blocking-sockets

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


Re: [Tutor] need help with a script..

2012-04-11 Thread Mark Lawrence

On 11/04/2012 14:50, Khalid Al-Ghamdi wrote:

Hi All,

I'm using python 3.2 on a windows xp.

I wrote the below script and ran it with the hope of returning a list of
proctors (list_proc), but when it runs it  doesn't call the function
convert_proctors() as intended. On the other hand, when i import the module
from the IDLE prompt and call the convert_proctors() function, the function
returns the desired list.

Why is this so?

Thanks


1. import csv
2.
3. proctor_file=r'c:\Python32\Khalid Stuff\Testing_Scheduler\p
roctors.csv'
4.
5.
6. def convert_proctors():
7. proctor_csv_reader = csv.reader(open(proctor_file))
8. proctor_list=list(proctor_csv_reader)
9. list_proc=[]
10. for row in range(len(proctor_list)):
11. list_proc.append(proctor_list[row][0])
12. return (list_proc)
13.
14.
15. convert_proctors()




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


Your main query has already been answered, but I'd like to point out 
that your function could be written something like this.


def convert_proctors():
list_proc = []
for row in csv.reader(open(proctor_file)):
list_proc.append(row[0])
return list_proc

--
Cheers.

Mark Lawrence.

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


Re: [Tutor] need help with a script..

2012-04-11 Thread Khalid Al-Ghamdi
got it thanks a lot

On Wed, Apr 11, 2012 at 4:59 PM, Jerry Hill  wrote:

> On Wed, Apr 11, 2012 at 9:50 AM, Khalid Al-Ghamdi 
> wrote:
> > Hi All,
> >
> > I'm using python 3.2 on a windows xp.
> >
> > I wrote the below script and ran it with the hope of returning a list of
> > proctors (list_proc), but when it runs it  doesn't call the function
> > convert_proctors() as intended. On the other hand, when i import the
> module
> > from the IDLE prompt and call the convert_proctors() function, the
> function
> > returns the desired list.
> >
> > Why is this so?
>
> When you run that code as a script, it does call your
> convert_proctors() function.  But since all you do is create a list,
> and you never save it to disk, or print it to the screen, or even
> assign it to a variable, the result is just thrown away.  Try changing
> the last line to:
>
> print(convert_proctors())
>
> and you'll see the results you were expecting.
>
> --
> Jerry
> ___
> 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] need help with a script..

2012-04-11 Thread Christian Witts

On 2012/04/11 03:50 PM, Khalid Al-Ghamdi wrote:

Hi All,

I'm using python 3.2 on a windows xp.

I wrote the below script and ran it with the hope of returning a list 
of proctors (list_proc), but when it runs it  doesn't call the 
function convert_proctors() as intended. On the other hand, when i 
import the module from the IDLE prompt and call the convert_proctors() 
function, the function returns the desired list.


Why is this so?

Thanks

1.
import csv
2.
3.
proctor_file=r'c:\Python32\Khalid
Stuff\Testing_Scheduler\proctors.csv'
4.
5.
6.
def convert_proctors():
7.
proctor_csv_reader = csv.reader(open(proctor_file))
8.
proctor_list=list(proctor_csv_reader)
9.
list_proc=[]
10.
for row in range(len(proctor_list)):
11.
list_proc.append(proctor_list[row][0])
12.
return (list_proc)
13.
14.
15.
convert_proctors()



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
convert_proctors() will get called when you run the application from say 
the command line, but because there's no explicit printing of the 
resulting list it will never get displayed to your console. Whereas when 
you run it from IDLE it will implicitly print the return value of a 
function if you do not "save" the data to a variable.

--

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


Re: [Tutor] need help with a script..

2012-04-11 Thread Jerry Hill
On Wed, Apr 11, 2012 at 9:50 AM, Khalid Al-Ghamdi  wrote:
> Hi All,
>
> I'm using python 3.2 on a windows xp.
>
> I wrote the below script and ran it with the hope of returning a list of
> proctors (list_proc), but when it runs it  doesn't call the function
> convert_proctors() as intended. On the other hand, when i import the module
> from the IDLE prompt and call the convert_proctors() function, the function
> returns the desired list.
>
> Why is this so?

When you run that code as a script, it does call your
convert_proctors() function.  But since all you do is create a list,
and you never save it to disk, or print it to the screen, or even
assign it to a variable, the result is just thrown away.  Try changing
the last line to:

print(convert_proctors())

and you'll see the results you were expecting.

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


Re: [Tutor] how to build a multiplayer game?

2012-04-11 Thread Jerry Hill
On Wed, Apr 11, 2012 at 9:30 AM, Surya K  wrote:
> Well, can we make the program so that user enters his IP, DNS addresses
> before starting?

You could, sure.  That's fine for testing purposes, but most people
don't know their own IP addresses.  Many people don't have a DNS entry
for their home PC.  Also, what about NAT?

> Don't you think DNS is required as IP addr may be same for some people in
> this world.. after all, we only have limited number of combinations.
> (xx.xx.xx.xx .. )

Again, not every computer has a DNS address.  If you are going to ask
a user to hand enter their IP address, it would make sense to accept
either a numeric IP address, or a DNS name.


> * I even got a wild idea, can't we use a IRC channel, create a group and we
> make sure that each user of the game will be a member of the group??

Sure, but now you have to write (or embed) an IRC client.  Do you need
to worry about someone joining your channel that isn't using your game
client?  Does that have potential security implications?

> approx, how much delay would be there??

That depends on the delay from each client to the IRC server.

> Hmm, google app engine is a nice option but thing is I don't know how to use
> it.

You're going to have to learn quite a bit about networking and
probably client / server architecture to write a networked game.

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


[Tutor] need help with a script..

2012-04-11 Thread Khalid Al-Ghamdi
Hi All,

I'm using python 3.2 on a windows xp.

I wrote the below script and ran it with the hope of returning a list of
proctors (list_proc), but when it runs it  doesn't call the function
convert_proctors() as intended. On the other hand, when i import the module
from the IDLE prompt and call the convert_proctors() function, the function
returns the desired list.

Why is this so?

Thanks


   1. import csv
   2.
   3. proctor_file=r'c:\Python32\Khalid Stuff\Testing_Scheduler\p
   roctors.csv'
   4.
   5.
   6. def convert_proctors():
   7. proctor_csv_reader = csv.reader(open(proctor_file))
   8. proctor_list=list(proctor_csv_reader)
   9. list_proc=[]
   10. for row in range(len(proctor_list)):
   11. list_proc.append(proctor_list[row][0])
   12. return (list_proc)
   13.
   14.
   15. convert_proctors()
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] python connect() function

2012-04-11 Thread Pierre Barthelemy
Hello,

I have a question about event handling and the use of the connect function.
I have a data object, that contains a series of signals, one being
"new_data_point" .

When i want to plot the data, i also connect the "new_data_point" event to
the function "analysis_client.update_plot". I therefore run the line:

data.connect('new_data_point', analysis_client.update_plot)

In this case, everytime the data object is updated, i also update the plot.


I would like to adapt this code to allow to have several plots, connected
to several data objects. I would therefore need to specify, when i connect
the "update_plot" function, which plots needs to be updated.
Is it possible to specify arguments to be used by the connected function
when the event occurs ? For instance, is there a way to write something
like:

data.connect('new_data_point',
analysis_client.update_plot(specific_plot_instance))

So that when the event occurs, the corresponding plot (and only this one)
is updated ?

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


Re: [Tutor] how to build a multiplayer game?

2012-04-11 Thread Surya K



> Date: Wed, 11 Apr 2012 06:42:40 -0400
> From: d...@davea.name
> To: sur...@live.com
> CC: tutor@python.org
> Subject: Re: [Tutor] how to build a multiplayer game?
> 
> On 04/11/2012 06:02 AM, Surya K wrote:
> >
> > I have written the basic part of the game. Now I want to make it a 
> > multiplayer one. (Its not a web app, a OS application)
> > So, I just wanted to know how do it.
> > Which topics I should refer? Network Programming or Web Programming or 
> > Internet Client Programming. 
> > (There were the topics mentioned in Core Python Programming book).
> >
> > Can anyone tell me how do we achieve such a application (I mean without 
> > having a web server). I am not really ready to setup a Apache HTTP 
> > server. and all.   
> >
> 
> You want to make two instances of the app talk to each other.  If
> they're on the same machine (unlikely for a real game, but might be used
> for testing), or if they're on the same local network, then the features
> you need are available in the stdlib.  If you're going out on the web,
> you need a host out there which will cooperate with the two apps (players).
> 
> Same local network:  Generally when both machines share a router or a
> wifi connection, and would get to the web through the same ISP
> connection.  If you figure out what their IP addresses are, they can
> talk directly, using sockets.
> 
Well, can we make the program so that user enters his IP, DNS addresses before 
starting?
Don't you think DNS is required as IP addr may be same for some people in this 
world.. after all, we only have limited number of combinations. (xx.xx.xx.xx .. 
)
* I even got a wild idea, can't we use a IRC channel, create a group and we 
make sure that each user of the game will be a member of the group??approx, how 
much delay would be there??

> Out on the web:  You need a server that's on the web that each machine
> can reach.  It doesn't have to be your own, and I can't recommend any
> particular one, but I'd bet google appserver would work.  For that
> matter, email would work, if you don't mind a pretty long delay between
> turns.
> 
Hmm, google app engine is a nice option but thing is I don't know how to use it.

> For any more specific advice, somebody else had better pop in.
> 
> -- 
> 
> DaveA
> 
> 
> 


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


Re: [Tutor] how to build a multiplayer game?

2012-04-11 Thread Dave Angel
On 04/11/2012 06:02 AM, Surya K wrote:
>
> I have written the basic part of the game. Now I want to make it a 
> multiplayer one. (Its not a web app, a OS application)
> So, I just wanted to know how do it.
> Which topics I should refer? Network Programming or Web Programming or 
> Internet Client Programming. 
> (There were the topics mentioned in Core Python Programming book).
>
> Can anyone tell me how do we achieve such a application (I mean without 
> having a web server). I am not really ready to setup a Apache HTTP 
> server. and all. 
>

You want to make two instances of the app talk to each other.  If
they're on the same machine (unlikely for a real game, but might be used
for testing), or if they're on the same local network, then the features
you need are available in the stdlib.  If you're going out on the web,
you need a host out there which will cooperate with the two apps (players).

Same local network:  Generally when both machines share a router or a
wifi connection, and would get to the web through the same ISP
connection.  If you figure out what their IP addresses are, they can
talk directly, using sockets.

Out on the web:  You need a server that's on the web that each machine
can reach.  It doesn't have to be your own, and I can't recommend any
particular one, but I'd bet google appserver would work.  For that
matter, email would work, if you don't mind a pretty long delay between
turns.

For any more specific advice, somebody else had better pop in.

-- 

DaveA



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


[Tutor] how to build a multiplayer game?

2012-04-11 Thread Surya K


I have written the basic part of the game. Now I want to make it a multiplayer 
one. (Its not a web app, a OS application)
So, I just wanted to know how do it.
Which topics I should refer? Network Programming or Web Programming or Internet 
Client Programming. 
(There were the topics mentioned in Core Python Programming book).

Can anyone tell me how do we achieve such a application (I mean without having 
a web server). I am not really ready to setup a Apache HTTP server. and 
all.   ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor