[Tutor] Using the TIME module to extract a semi-random number

2009-09-18 Thread Katt
- Original Message - Message: 1 Date: Wed, 16 Sep 2009 23:19:39 -0400 From: Kent Johnson To: Laurii Cc: tutor@python.org Subject: Re: [Tutor] Using the time module to extract a semi-random number Message-ID: <1c2a2c590909162019l364b516cifcd2e0befe2ad...@mail.gmail.com> Content-Type: t

Re: [Tutor] Calling a dictionary entry inside of a function

2009-09-18 Thread Alan Gauld
Corey Richardson wrote: I am trying to use a parameter of a function to call a word inside a dictionary. Here is my code wordList = { 'Apple' : ["A delicious snack"], 'Word' : ["This code is not working..."], } def define(word): print wordList['Word'] You put quotess around word whic

Re: [Tutor] Calling a dictionary entry inside of a function

2009-09-18 Thread Benno Lang
On Sat, Sep 19, 2009 at 9:27 AM, Corey Richardson wrote: > I am trying to use a parameter of a function to call a word inside a > dictionary. > Here is my code > wordList = { >   'Apple' : ["A delicious snack"], >   'Word' : ["This code is not working..."], > } > def define(word): >   print wordLi

[Tutor] Calling a dictionary entry inside of a function

2009-09-18 Thread Corey Richardson
I am trying to use a parameter of a function to call a word inside a dictionary. Here is my code wordList = { 'Apple' : ["A delicious snack"], 'Word' : ["This code is not working..."], } def define(word): print wordList['Word'] When I use define('Apple') it returns ['This code is not w

Re: [Tutor] Python decorator to ensure that kwargs are correct

2009-09-18 Thread Rich Lovely
Should probably clean up my code properly before submitting, to hide some of the noobish errors like forgetting to put quotes round strings... >>> class Demo(object): ... def __init__(self, name="", surname="", age=0): ... print name, surname, age ... >>> Demo(name='Ri

Re: [Tutor] Python decorator to ensure that kwargs are correct

2009-09-18 Thread Rich Lovely
2009/9/18 Manuel de la Pena : > Hello, > > > I have done a decorator that I used to ensure that the keyword arguments > passed to a constructor are the correct/expected ones. The code is the > following: > > from functools import wraps > > def keyargs_check(keywords): > """ > This decorator ensure

Re: [Tutor] Tutor Digest, Vol 67, Issue 62

2009-09-18 Thread Corey Richardson
I'm going to be making a simple program, that is a few books like "A is for...", "B is for...", but it will be many built into one, Sorry, I don't understand? *By that, I mean it will be like a childrens book, teaching the letters. You've read them. example "A is for apple, a yummy tre

Re: [Tutor] Import vs #include

2009-09-18 Thread Kent Johnson
On Fri, Sep 18, 2009 at 4:15 PM, Warren Marshall wrote: > > Excellent, OK, this is becoming clearer ... > > So if I wanted a common library of code that several Python apps would be > using, best practices would say I should put that into a directory that the > projects can see and import it as a

Re: [Tutor] Determine Filetype

2009-09-18 Thread Kent Johnson
On Fri, Sep 18, 2009 at 4:10 PM, ad...@gg-lab.net wrote: > Ok, so magic is not installed on GAE. I've then uploaded it and it > loaded succesfully. New error: > > No module named _ctypes > > And, reading the full debug i got this: > > File "/base/python_dist/lib/python2.5/ctypes/__init__.py", lin

Re: [Tutor] order data

2009-09-18 Thread Sander Sweers
2009/9/18 Rayon : I will assume array == python list. > I have a array with this data in it How are you reading the data? Do you convert all the numbers to floats? If so you will need to think about precision of the floats. If you want to preserve the precision look into the decimal module. > 0

Re: [Tutor] Import vs #include

2009-09-18 Thread Warren Marshall
Excellent, OK, this is becoming clearer ... So if I wanted a common library of code that several Python apps would be using, best practices would say I should put that into a directory that the projects can see and import it as a package.module. Cool... - Warren (epic...@gmail.com) On

Re: [Tutor] Determine Filetype

2009-09-18 Thread ad...@gg-lab.net
Ok, a good news for me: i've modified my script, adding a: import magic line at the top of it. But I got this error: No module named magic Ok, so magic is not installed on GAE. I've then uploaded it and it loaded succesfully. New error: No module named _ctypes And, reading the full debug i g

[Tutor] Python decorator to ensure that kwargs are correct

2009-09-18 Thread Manuel de la Pena
Hello, I have done a decorator that I used to ensure that the keyword arguments passed to a constructor are the correct/expected ones. The code is the following: from functools import wraps def keyargs_check(keywords): """ This decorator ensures that the keys passed in kwargs are the onces tha

[Tutor] order data

2009-09-18 Thread Rayon
I have a array with this data in it 0.0046,0.095,0.0904,521456,['MCI 521456 0.0904'],['ATT 521 0.0919'],['IDT 521 0.095'],['None'] 0.0083,0.0192,0.0109,39023821,['MCI 39023821 0.0109'],['ATT 39 0.012'],['IDT 39 0.0192'],['SPR 39 0.0135'] 0.0421,0.0681,0.026,73462,['MCI 73462 0.0260'],['ATT 7 0.

Re: [Tutor] ODBC SQL Server Question

2009-09-18 Thread Jeff Johnson
Thanks for the clarification Kent! Kent Johnson wrote: On Fri, Sep 18, 2009 at 2:14 PM, Jeff Johnson wrote: Kent: How about this: self.cursor.execute("SELECT CUSTID FROM Stories WHERE NAME = '%s'" % (name, )) No, that has the same result as your original. For example, In [3]: name = "Kent';

Re: [Tutor] Determine Filetype

2009-09-18 Thread ad...@gg-lab.net
Oh, i'm sorry. I've read the README, but haven't noticed that m.from_buffer(open("testdata/test.pdf").read(1024)) was exactly what i was looking for. Ok, i'll try it and let you know :D 2009/9/18 Kent Johnson : > On Fri, Sep 18, 2009 at 2:21 PM, ad...@gg-lab.net wrote: >> Hi Emile, >> >> that

Re: [Tutor] Image manipluation (On-the-fly thumbnail creation)

2009-09-18 Thread dan06
Patrick Sabin wrote: > > When I needed thumbnails of my images, I created them using ImageMagick. > ImageMagick is a very nice tool for editing images and since it is > called from the command line it is easy to invoke it from a programming > language. There are python-bindings for it, but

Re: [Tutor] Determine Filetype

2009-09-18 Thread Kent Johnson
On Fri, Sep 18, 2009 at 2:21 PM, ad...@gg-lab.net wrote: > Hi Emile, > > that functions requires a filename/path. Did you even look at the link? There is a from_buffer() method also. Kent > 2009/9/18 Emile van Sebille : >> I'd take a look at python-magic at >> http://hupp.org/adam/hg/python-ma

Re: [Tutor] Import vs #include

2009-09-18 Thread Kent Johnson
On Fri, Sep 18, 2009 at 2:14 PM, Warren Marshall wrote: > > I'm trying to get my head around the organization of a larger Python > project. > > 1. Am I right in thinking that in Python, you don't have the concept of > something like a precompiled header and that every file that wants to use, > say

Re: [Tutor] ODBC SQL Server Question

2009-09-18 Thread Kent Johnson
On Fri, Sep 18, 2009 at 2:14 PM, Jeff Johnson wrote: > Kent: > > How about this: > self.cursor.execute("SELECT CUSTID FROM Stories WHERE NAME = '%s'" % (name, > )) No, that has the same result as your original. For example, In [3]: name = "Kent'; drop table Stories;--" In [4]: "SELECT CUSTID FRO

[Tutor] Import vs #include

2009-09-18 Thread Warren Marshall
I'm trying to get my head around the organization of a larger Python project. 1. Am I right in thinking that in Python, you don't have the concept of something like a precompiled header and that every file that wants to use, say "vector.py" needs to import that module? 2. How are Python

Re: [Tutor] Determine Filetype

2009-09-18 Thread ad...@gg-lab.net
Hi Emile, that functions requires a filename/path. Just like this one (for images) http://docs.python.org/library/imghdr.html Ok, i don't have a filename. I get the file from a BLOB in a db. Any idea? Thankyou for your precious help. 2009/9/18 Emile van Sebille : > On 9/18/2009 10:05 AM ad...@

Re: [Tutor] Calling VB.NET code with Python .. VB.net - Python integration ..

2009-09-18 Thread bob gailer
Otonicar Ales wrote: The idea is that Python calls VB.net program. VB.Net program gets data and than forward data back to Python for further processing.. One way to do this is by compiling vb.net program to exe. And than call exe by Python code. Data exchange goes via Access Data Base (P

Re: [Tutor] ODBC SQL Server Question

2009-09-18 Thread Jeff Johnson
Kent: How about this: self.cursor.execute("SELECT CUSTID FROM Stories WHERE NAME = '%s'" % (name, )) Question, does execute know to substitute the question mark with name? self.cursor.execute("SELECT CUSTID FROM Stories WHERE NAME= ?", (name, )) TIA Kent Johnson wrote: On Fri, Sep 18, 2009

Re: [Tutor] Determine Filetype

2009-09-18 Thread Emile van Sebille
On 9/18/2009 10:05 AM ad...@gg-lab.net said... Hi, i'm putting file in a DB as BLOB entries. To serve them, i need to take Content-Type headers. So, i'm looking for a function that returnes the filetype, given a data str. I've found many other topics like this in python mail-archive, but any o

[Tutor] Determine Filetype

2009-09-18 Thread ad...@gg-lab.net
Hi, i'm putting file in a DB as BLOB entries. To serve them, i need to take Content-Type headers. So, i'm looking for a function that returnes the filetype, given a data str. I've found many other topics like this in python mail-archive, but any of them contains the solution. Can you help me, p

Re: [Tutor] ODBC SQL Server Question

2009-09-18 Thread Kent Johnson
On Fri, Sep 18, 2009 at 11:49 AM, Jeff Johnson wrote: > Kristina: > > I would format it as follows: > > self.cursor.execute("SELECT CUSTID FROM Stories WHERE NAME = '%s'" % name) No, that is a recipe for SQL injection attacks such as this: http://xkcd.com/327/ >> self.cursor.execute("SELECT CUST

Re: [Tutor] ODBC SQL Server Question

2009-09-18 Thread Jeff Johnson
Kristina: I would format it as follows: self.cursor.execute("SELECT CUSTID FROM Stories WHERE NAME = '%s'" % name) Kristina Ambert wrote: Hi, Is anyone familiar with this error: dbi.internal-error: [Microsoft][SQL Server Driver]Invalid cursor state in EXEC This error is triggered by the firs

[Tutor] ODBC SQL Server Question

2009-09-18 Thread Kristina Ambert
Hi, Is anyone familiar with this error: dbi.internal-error: [Microsoft][SQL Server Driver]Invalid cursor state in EXEC This error is triggered by the first sql statement call in an accessor module which purpose is only to get data from a source module and feed it into a database: self.cursor.execu

Re: [Tutor] Executing a command from a specific directory

2009-09-18 Thread Kurt Bendl
Hello, On Sep 18, 2009, at 5:16 AM, Ansuman Dash wrote: I have written it like that. It is like press 1 and it ll download file1 and press 2 it ll download file2 etc But my question was I am using "time.sleep()" to make my script to wait for the file download and then validate it in lo

[Tutor] Calling VB.NET code with Python .. VB.net - Python integration ..

2009-09-18 Thread Otonicar Ales
The idea is that Python calls VB.net program. VB.Net program gets data and than forward data back to Python for further processing.. One way to do this is by compiling vb.net program to exe. And than call exe by Python code. Data exchange goes via Access Data Base (Python write in MC Acces

Re: [Tutor] Fw: utf locale sorting

2009-09-18 Thread Igor Mavrović - ma...@irb
Excellent, the thing works! Thanx a lot! - Original Message - From: Kent Johnson To: Igor Mavrović - ma...@irb Cc: Rich Lovely ; tutor@python.org Sent: Wednesday, September 16, 2009 7:06 PM Subject: Re: [Tutor] Fw: utf locale sorting How about this (assuming both argume

Re: [Tutor] Using the time module to extract a semi-random number

2009-09-18 Thread Kent Johnson
On Thu, Sep 17, 2009 at 4:59 PM, Katt wrote: > > - Original Message - From: "Kent Johnson" >> time.localtime().tm_sec will give you the number of >seconds as an >> integer without any conversions. > > Thank you for your quick response.  I didn't expect to get a response for a > couple of

Re: [Tutor] Executing a command from a specific directory

2009-09-18 Thread Sander Sweers
On Fri, 2009-09-18 at 14:46 +0530, Ansuman Dash wrote: > I have written it like that. It is like press 1 and it ll download > file1 and > press 2 it ll download file2 etc But without providing people how you accomplish this there is no way to help. > But my question was I am using "time.sleep

Re: [Tutor] Executing a command from a specific directory

2009-09-18 Thread Lie Ryan
Ansuman Dash wrote: Hi, I have written it like that. It is like press 1 and it ll download file1 and press 2 it ll download file2 etc What is "like that"? We are not psychic that could read your mind... Describe the way you downloaded the file. __

Re: [Tutor] html color coding: where to start

2009-09-18 Thread عماد نوفل
On Thu, Sep 17, 2009 at 7:24 PM, Kent Johnson wrote: > 2009/9/17 Emad Nawfal (عماد نوفل) : > > Hi Tutors, > > I want to color-code the different parts of the word in a morphologically > > complex natural language. The file I have looks like this, where the > fisrt > > column is the word, and the

Re: [Tutor] Executing a command from a specific directory

2009-09-18 Thread Ansuman Dash
Hi, I have written it like that. It is like press 1 and it ll download file1 and press 2 it ll download file2 etc But my question was I am using "time.sleep()" to make my script to wait for the file download and then validate it in log file, so is there any other way I can synchronize my code