[Tutor] Top Programming Languages of 2013

2007-10-07 Thread Dick Moores
http://www.redcanary.ca/view/top-programming Dick Moores ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Random module help

2007-10-07 Thread Norman Khine
Thank you, this is great. Alan Gauld wrote: Norman Khine [EMAIL PROTECTED] wrote q_keys.sort() a = [q[x] for x in q_keys] a = [random.choice(q[x]) for x in q_keys] So from this how do I choose a random element and produce a new dictionary like for example: See above. --

Re: [Tutor] a code question, but don't know question's name

2007-10-07 Thread Alan Gauld
Happy Deer [EMAIL PROTECTED] wrote def getdata(varlist): eventually I have a variable called data, which have exactly the same number of columns as the name of variables in varlist. Say varlist=['var1','var2','var3']. I want to assign var1=data[:,0], var2=data[:,1],

Re: [Tutor] Top Programming Languages of 2013

2007-10-07 Thread Alan Gauld
Dick Moores [EMAIL PROTECTED] wrote http://www.redcanary.ca/view/top-programming Interesting, but I'm not sure what the criteria for top is. Is it a measure of power, popularity, usage? Scary that HTML/CSS should be so high though given its not a programming language at all! Alan G.

Re: [Tutor] Top Programming Languages of 2013

2007-10-07 Thread Ricardo Aráoz
Alan Gauld wrote: Dick Moores [EMAIL PROTECTED] wrote http://www.redcanary.ca/view/top-programming Interesting, but I'm not sure what the criteria for top is. Is it a measure of power, popularity, usage? Scary that HTML/CSS should be so high though given its not a programming

[Tutor] Top Programming Languages of 2013

2007-10-07 Thread Adam Bark
On 07/10/2007, Ricardo Aráoz [EMAIL PROTECTED] wrote: Alan Gauld wrote: Dick Moores [EMAIL PROTECTED] wrote http://www.redcanary.ca/view/top-programming Interesting, but I'm not sure what the criteria for top is. Is it a measure of power, popularity, usage? Scary that HTML/CSS

Re: [Tutor] Top Programming Languages of 2013

2007-10-07 Thread James Matthews
What are these stats based on? On 10/7/07, Alan Gauld [EMAIL PROTECTED] wrote: Dick Moores [EMAIL PROTECTED] wrote http://www.redcanary.ca/view/top-programming Interesting, but I'm not sure what the criteria for top is. Is it a measure of power, popularity, usage? Scary that HTML/CSS

Re: [Tutor] a code question, but don't know question's name

2007-10-07 Thread Kent Johnson
Alan Gauld wrote: The notation data[;,0] doesn't make sense and is an error in Python. I#m not sure what you think it does. I assume you simply mean data[0]? [:,0] is an extended slice, not an error: http://docs.python.org/ref/slicings.html It is used in Numeric/numpy to select from

Re: [Tutor] largest and smallest numbers

2007-10-07 Thread Kent Johnson
Christopher Spears wrote: One of the exercises from Core Python Programmng (2nd Edition) asks me to determine the largest and smallest integers, float, and complex numbers my system can handle. Using python.org and Google, I have discovered my system's largest and smallest ingtegers:

Re: [Tutor] a code question, but don't know question's name

2007-10-07 Thread Alan Gauld
Kent Johnson [EMAIL PROTECTED] wrote The notation data[;,0] doesn't make sense and is an error in Python. [:,0] is an extended slice, not an error: http://docs.python.org/ref/slicings.html Really? I got an error from the interpreter. d[:,0] Traceback (most recent call last): File

Re: [Tutor] a code question, but don't know question's name

2007-10-07 Thread Kent Johnson
Alan Gauld wrote: Kent Johnson [EMAIL PROTECTED] wrote The notation data[;,0] doesn't make sense and is an error in Python. [:,0] is an extended slice, not an error: http://docs.python.org/ref/slicings.html Really? I got an error from the interpreter. d[:,0] Traceback (most recent

Re: [Tutor] a code question, but don't know question's name

2007-10-07 Thread Kent Johnson
Kent Johnson wrote: Alan Gauld wrote: Kent Johnson [EMAIL PROTECTED] wrote The notation data[;,0] doesn't make sense and is an error in Python. [:,0] is an extended slice, not an error: http://docs.python.org/ref/slicings.html We discussed this quite a bit last July:

[Tutor] File Writing Permission?

2007-10-07 Thread David Millar
Hi everyone, I'm working on making a Debian package for a game I'm working on, and it works fine, but I've run into a problem with my script now. The script is placed in /usr/bin so all users on the system have access, but even though it will run fine, I can't save files to that directory, so the

[Tutor] Logging with proper format

2007-10-07 Thread wormwood_3
Hello tutors, I am adding logging to a program I am writing. I have some messages I want to log that are rather long. The problem I am running into is that when the line is more than the 80 character line recommendation and I split it across 2 lines with \, the output is affected. Example

Re: [Tutor] a code question, but don't know question's name

2007-10-07 Thread Happy Deer
Thank all for the discussion. Maybe I can separate my question into two. First, I have experience in Matlab, where I can use eval. I wonder whether someone knows about it. Second, if I just want to return data[:,1], ...data[:,-1] separately without knowing ahead how many columns data has. What

[Tutor] Logging with proper format

2007-10-07 Thread wormwood_3
Sent this almost an hour ago, did not get it from the list yet. No idea why, but sending again... -- Hello tutors, I am adding logging to a program I am writing. I have some messages I want to log that are rather long. The problem I am running into is that when the line

Re: [Tutor] File Writing Permission?

2007-10-07 Thread Eric Brunson
David Millar wrote: Hi everyone, I'm working on making a Debian package for a game I'm working on, and it works fine, but I've run into a problem with my script now. The script is placed in /usr/bin so all users on the system have access, but even though it will run fine, I can't save

[Tutor] corresponding command in Python to eval in Matlab

2007-10-07 Thread Happy Deer
Dear all- I wonder whether there is a way in Python which can do what eval in Matlab does. Say, varlist is a 1 by k tuple/list, which contains strings for variable names. For example, varlist=['var1','var2',...'vark'] data is a n by k matrix. I want to assign each column in data to each variable

Re: [Tutor] a code question, but don't know question's name

2007-10-07 Thread Eric Brunson
Happy Deer wrote: Thank all for the discussion. Maybe I can separate my question into two. First, I have experience in Matlab, where I can use eval. I wonder whether someone knows about it. Second, if I just want to return data[:,1], ...data[:,-1] separately without knowing ahead how

Re: [Tutor] a code question, but don't know question's name

2007-10-07 Thread Happy Deer
I am writing a function getdata for other people, and I want others can use the function as follows. var1,var2, var3=getdata(..., ['var1','var2','var3'],...) If I can not return data column by column, I can not get the above, right? On 10/7/07, Eric Brunson [EMAIL PROTECTED] wrote: Happy Deer

Re: [Tutor] File Writing Permission?

2007-10-07 Thread claxo
if os.name == posix: fname = ~/ + fname infile = open(fname,w) you must expand '~' before open: fname = os.path.join('~',fname) fname = os.path.expanduser( fname ) infile = open(fname,'w') ___ Tutor

Re: [Tutor] Logging with proper format

2007-10-07 Thread claxo
dont indent the line after '\', that means 0 indent s = 'hello\ boy' ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] a code question, but don't know question's name

2007-10-07 Thread Kent Johnson
Happy Deer wrote: First, I have experience in Matlab, where I can use eval. I wonder whether someone knows about it. Python has an eval() function but it's use is discouraged, there is usually a better way. It would help if you would give us more context for your problem. Second, if I

Re: [Tutor] a code question, but don't know question's name

2007-10-07 Thread Eric Brunson
Happy Deer wrote: I am writing a function getdata for other people, and I want others can use the function as follows. var1,var2, var3=getdata(..., ['var1','var2','var3'],...) If I can not return data column by column, I can not get the above, right? Given: data = [ 1, 2, 3, 4, 5, 6 ]

Re: [Tutor] corresponding command in Python to eval in Matlab

2007-10-07 Thread Eric Brunson
A good python coder would probably not choose to pollute his name space like that. My choice would be to assign the elements of data to a dictionary indexed by the strings in varlist like this: vardict = dict( zip( varlist, data ) ) and reference var1 as: vardict['var1'] Happy Deer wrote:

Re: [Tutor] Logging with proper format

2007-10-07 Thread Eric Brunson
claxo wrote: dont indent the line after '\', that means 0 indent s = 'hello\ boy' Or, arguably better: s = '''hello boy''' ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Logging with proper format

2007-10-07 Thread Kent Johnson
wormwood_3 wrote: Hello tutors, I am adding logging to a program I am writing. I have some messages I want to log that are rather long. The problem I am running into is that when the line is more than the 80 character line recommendation and I split it across 2 lines with \, the output

Re: [Tutor] a code question, but don't know question's name

2007-10-07 Thread Kent Johnson
Happy Deer wrote: I am writing a function getdata for other people, and I want others can use the function as follows. var1,var2, var3=getdata(..., ['var1','var2','var3'],...) There is no need to pass the variable names to getdata. Have you read any Python tutorials? There are several good

Re: [Tutor] corresponding command in Python to eval in Matlab

2007-10-07 Thread Eric Brunson
However, I didn't actually answer your question. As Kent has already mentioned, eval is quite dangerous in python and to be avoided when possible. I think it would be safer to do something like this: l = locals() for x, y in zip( varlist, data ): l[x] = y or, more tersely: [

Re: [Tutor] corresponding command in Python to eval in Matlab

2007-10-07 Thread Kent Johnson
Happy Deer wrote: Dear all- I wonder whether there is a way in Python which can do what eval in Matlab does. Say, varlist is a 1 by k tuple/list, which contains strings for variable names. For example, varlist=['var1','var2',...'vark'] data is a n by k matrix. I want to assign each

Re: [Tutor] Logging with proper format

2007-10-07 Thread Kent Johnson
Eric Brunson wrote: claxo wrote: dont indent the line after '\', that means 0 indent s = 'hello\ boy' Or, arguably better: s = '''hello boy''' That is a different string, it contains a newline, the original does not: In [20]: s = 'hello\ : boy' In [21]: s2 = '''hello

Re: [Tutor] corresponding command in Python to eval in Matlab

2007-10-07 Thread Kent Johnson
Eric Brunson wrote: However, I didn't actually answer your question. As Kent has already mentioned, eval is quite dangerous in python and to be avoided when possible. I think it would be safer to do something like this: l = locals() for x, y in zip( varlist, data ): l[x] = y

Re: [Tutor] Logging with proper format

2007-10-07 Thread R. Alan Monroe
logger.info(Checked %s records in %s seconds, yielding an average of \ %s seconds per record. % (len(self.data), duration, avgquery) ) ^ Remove these spaces. It makes the source code look weird, but the output will be correct. Alan

Re: [Tutor] a code question, but don't know question's name

2007-10-07 Thread Eike Welk
On Sunday 07 October 2007 21:29, Happy Deer wrote: Thank all for the discussion. Maybe I can separate my question into two. First, I have experience in Matlab, where I can use eval. I wonder whether someone knows about it. I suspect you are using Numpy, you should subscribe to the Numpy

Re: [Tutor] Logging with proper format

2007-10-07 Thread Eike Welk
On Sunday 07 October 2007 22:32, Kent Johnson wrote: Eric Brunson wrote: claxo wrote: dont indent the line after '\', that means 0 indent s = 'hello\ boy' Or, arguably better: s = '''hello boy''' And there is even a third way:-) s = hello \ ... world. s 'hello

Re: [Tutor] a code question, but don't know question's name

2007-10-07 Thread Eike Welk
I have written the exact same reply. Sorry for that! I should have read the other replies first. Eike. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

[Tutor] Permission Report

2007-10-07 Thread Stephen Nelson-Smith
Hello all, I have a tree of code on a machine which has been tweaked and fiddled with over several months, and which passes tests. I have the same codebase in a new virtual machine. A shell hack[0] shows me that the permissions are very different between the two. I could use rsync or something

Re: [Tutor] Permission Report

2007-10-07 Thread Alan Gauld
Stephen Nelson-Smith [EMAIL PROTECTED] wrote I could use rsync or something to synchronise them, but I would like to produce a report of the sort: Change file: foo from 755 to 775 I'm not sure how best to proceed - I guess walk through the filesystem gathering info using stat, then do

[Tutor] Updating MySQL Database

2007-10-07 Thread wormwood_3
Hello all, I have a script which takes data from a file or MySQL DB, looks up some stuff, then can print results to console or file. I would also like it to be able to update a MySQL database with the results. Does anyone have any ideas on how to do this? I can update records just fine, but

Re: [Tutor] Updating MySQL Database

2007-10-07 Thread Ricardo Aráoz
wormwood_3 wrote: Hello all, I have a script which takes data from a file or MySQL DB, looks up some stuff, then can print results to console or file. I would also like it to be able to update a MySQL database with the results. Does anyone have any ideas on how to do this? I can update

Re: [Tutor] Permission Report

2007-10-07 Thread Kent Johnson
Alan Gauld wrote: There is a dircmp module that may do what you want but I've not used it. It was deprecated in Python 2.0 and removed in 2.5. From a quick look it might provide a useful framework but it doesn't compare permissions. Kent ___ Tutor

Re: [Tutor] Updating MySQL Database

2007-10-07 Thread Kent Johnson
wormwood_3 wrote: Hello all, I have a script which takes data from a file or MySQL DB, looks up some stuff, then can print results to console or file. I would also like it to be able to update a MySQL database with the results. Does anyone have any ideas on how to do this? I can update

Re: [Tutor] Updating MySQL Database

2007-10-07 Thread Rick Pasotto
On Sun, Oct 07, 2007 at 06:07:45PM -0700, wormwood_3 wrote: Hello all, I have a script which takes data from a file or MySQL DB, looks up some stuff, then can print results to console or file. I would also like it to be able to update a MySQL database with the results. Does anyone have any

Re: [Tutor] Updating MySQL Database

2007-10-07 Thread Eric Walstad
Hey Sam, wormwood_3 wrote: Hello all, I have a script which takes data from a file or MySQL DB, looks up some stuff, then can print results to console or file. I would also like it to be able to update a MySQL database with the results. Does anyone have any ideas on how to do this? I can

Re: [Tutor] File Writing Permission?

2007-10-07 Thread David Millar
Thanks - it still took a bit more tweaking because of how I wrote a few things, but the saving works fine now. I've been having trouble with finding a version of the curses library for Windows that I can get working, so I just used os.path.expanduser no matter the system. :/ Dave On 10/7/07,

Re: [Tutor] Updating MySQL Database

2007-10-07 Thread Steve Willoughby
Rick Pasotto wrote: (ip,fqdn) = line.split(',') updatequery = update resultstable set %s where ip = %s % (fqdn,ip) cursor.execute(updatequery) connection.close() Alternatively you could do: connection = MySQLdb.connect(db=self.todatabase,host-self.host,