Re: [Tutor] saving a numpy ndarray in sqlite3 (markus kossner)

2009-12-21 Thread Don Jennings
I am not familiar with numpy, but you might like to take a look at  
y_serial which allows you to store python objects in sqlite:


http://yserial.sourceforge.net/

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


[Tutor] securely transmitting data via email

2005-06-01 Thread Don Jennings
Goal:  to securely transmit data (collected on a form on a secure web 
site) to recipient

Possible solutions, thus far:

1) create web page accessible through HTTPS; email link to recipient, 
BUT that adds extra steps for him. I'd like it to be as transparent as 
possible (doesn't everyone? ; >)

2) use cryptography directly in the python CGI program (e.g. ezPyCrypto 
or SSLCrypto) and email the results. I am assuming that I can import a 
public key created by PGP or GnuPG

3) os.popen (after sanitizing the input, of course) to use the command 
line interface of GnuPG to create an encrypted file and attaching that 
to an email

Anyone have experience achieving this goal? Have I overlooked other 
options? Sample programs, maybe?

Thanks!
Don

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] thanks!

2005-09-23 Thread Don Jennings
Hi, everyone. Just a note of thanks to all of you who participate on 
the tutor list. I recently finished my first python CGI program, but I 
didn't have to post a lot of questions because most had been asked and 
answered already : >) For example, I wondered how to get unique file 
names for dynamic creation of web pages (answer: tempfile module). Keep 
up the great work.

Thanks again,
Don

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] web development

2005-09-27 Thread Don Jennings
Earlier this month, Kent posted that Jython and Velocity are a good way 
to develop dynamic web sites. After a little searching, it seems that 
there are quite a few options for web development in Python (perhaps 
too many?). So, rather than ask for recommendations of which one to 
use, what I would really like to know are how people decided to use any 
particular framework.

Thanks!
Don

P.S. As an aside, does anyone have any experience with django? (I 
really like the name since I am fond of django reinhardt, the jazz 
guitarist.)

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [OT] Python Tutor like java mailing list

2006-01-01 Thread Don Jennings
I suggest the beginners' forum at javaranch.com (they even give away 
free books on occasion : >)

http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=forum&f=33

Take care,
Don

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] build list of non-empty variables

2008-07-08 Thread Don Jennings
Hi, folks.

>From within a class, I want to return a string with data from non-empty
variables in a class.

I could create a list of all the variables and then iterate over them,
dropping the ones which are empty, then join() and return them; however, I
am guessing there is another way to get that list of variables or to
accomplish my goal. Suggestions?

Thanks!
Don
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] build list of non-empty variables

2008-07-08 Thread Don Jennings
("Duh! Code would be good," says newbie to himself.)

Here's an example from django which I am using, but I asked on this list
since it seems more related to python than the web framework:

class Contact(models.Model):
first_name = models.CharField(max_length=30, blank=True)
last_name = models.CharField(max_length=30, blank=True)
email = models.EmailField(blank=True)
phone = models.PhoneNumberField()

def __unicode__(self):
l=[self.first_name, self.last_name, self.email, self.phone]
res=[]

for x in l:
if x != '':
res.append(x)

return ';'.join(res)

Thanks!
Don


On Tue, Jul 8, 2008 at 11:56 AM, Kent Johnson <[EMAIL PROTECTED]> wrote:

> On Tue, Jul 8, 2008 at 9:14 AM, Don Jennings <[EMAIL PROTECTED]> wrote:
> > Hi, folks.
> >
> > From within a class, I want to return a string with data from non-empty
> > variables in a class.
> >
> > I could create a list of all the variables and then iterate over them,
> > dropping the ones which are empty, then join() and return them; however,
> I
> > am guessing there is another way to get that list of variables or to
> > accomplish my goal. Suggestions?
>
> It would help to see code that works according to your suggestion.
>
> Where do the variables come from? Do you mean a list of all the
> attributes in an instance of a class? A list comprehension is often
> useful for creating a filtered list but I don't know if it will work
> for you without understanding better what you want to do.
>
> Kent
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] build list of non-empty variables

2008-07-09 Thread Don Jennings
Ah! A list comprehension. Not at that point in the learning python book,
yet, but I will be soon. Thanks!
Don

On Tue, Jul 8, 2008 at 9:34 PM, Kent Johnson <[EMAIL PROTECTED]> wrote:

> On Tue, Jul 8, 2008 at 6:35 PM, Don Jennings <[EMAIL PROTECTED]> wrote:
>
> > def __unicode__(self):
> > l=[self.first_name, self.last_name, self.email, self.phone]
> > res=[]
> >
> > for x in l:
> > if x != '':
> > res.append(x)
> >
> > return ';'.join(res)
>
> return ';'.join(x for x in l if x)
> will work.
>
> Kent
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] deltatime difficulty

2008-09-18 Thread Don Jennings
On 9/18/08, Wayne Watson <[EMAIL PROTECTED]> wrote:
> What's the problem here. It seems right to me. line 9 is diff =...
>>
>> import time
>> from datetime import datetime
>> def adjust_ftime(afilename, sec):
>> # Vmmdd_hhmmss+tag, seconds in, new mmdd_hhmmss out
>> ts = afilename[1:-7]  # use time stamp portion
>> format = '%Y%m%d_%H%M%S'
>> d = datetime(*(time.strptime(ts, format)[0:6]))
>> print "sec: ", sec, type(d)
>> diff = datetime.timedelta(seconds = sec)
>> print type(diff)
>> d = d + diff
>> return d.strftime(format)
>>
>> adjust_ftime('v20080120_20.xx.dat',  33)
>
>
> Results:
> sec:  33 
> Traceback (most recent call last):
>   File
> "C:/Sandia_Meteors/Improved_Sentinel/Sentinel_Playground/Utility_Dev/junk.py",
> line 14, in ?
> adjust_ftime('v20080120_20.xx.dat', 33)
>   File
> "C:/Sandia_Meteors/Improved_Sentinel/Sentinel_Playground/Utility_Dev/junk.py",
> line 9, in adjust_ftime
> diff = datetime.timedelta(seconds = sec)
> AttributeError: type object 'datetime.datetime' has no attribute 'timedelta'
>


Wayne,

You only imported datetime from the datetime module. If you want to
use timedelta, you'll need to import that, too. Then your line 9
becomes:

diff = timedelta(seconds = sec)

Take care,
Don
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] optparse example

2008-09-22 Thread Don Jennings
On 9/22/08, Tasos Latsas <[EMAIL PROTECTED]> wrote:
> Hello list,
> I tried the optparse example from the python library reference and it
> doesn't seem to work..what am I doing wrong?
> I keep getting the "incorrect number of arguments" message although i
> use the correct number..

Actually, you aren't using the correct number of arguments for the
code as written. This line:

if len(args) != 1:
parser.error("incorrect number of arguments")

checks to see if the arguments, not to be confused with the options,
are greater than one. So, one way you might call the script would be:

python parser.py somefile.txt

Take care,
Don
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] cgi scripts

2008-11-08 Thread Don Jennings
(Oops! Forgot to include tutor in recipient.)

On 11/8/08, Don Jennings <[EMAIL PROTECTED]> wrote:
> Hi, Jim. Actually, improper HTML would cause a problem with the
> browser and what it may or may not display. An "Internal Server Error"
> does indicate that you had a problem with your code. I suggest
> referring back to Alan's post again.
>
> Take care,
> Don
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Leaving PHP for Python

2008-11-25 Thread Don Jennings
Oops, I meant to say that django "has EXCELLENT documentation"

Take care,
Don

On 11/25/08, Don Jennings <[EMAIL PROTECTED]> wrote:
> Welcome! I suggest you take a look at django [1]. You'll find that it
> has documentation [2] and an active developer community [3]. Of
> course, for your questions about learning python, you've already found
> a very helpful community : >)
>
> Take care,
> Don
>
> [1]  http://www.djangoproject.com/
> [2] http://docs.djangoproject.com/en/dev/
> [3] http://www.djangoproject.com/community/
>
> On 11/25/08, Jason DeBord <[EMAIL PROTECTED]> wrote:
>> Hello All,
>>
>> This is my first message on the mailing list. I am excited to get started
>> developing content / backend for the web with Python.
>>
>> I have a background in PHP, but am convinced that Python is a better, more
>> powerful language.
>>
>> I am on a Windows XP machine and I have been using XAMPP for server, php,
>> mysql...
>>
>> I installed Python 2.5 and mod_python successfully. I can serve pages with
>> .py extension to http://localhost .
>>
>> The following for example:
>>
>> from mod_python import apache
>>
>> def handler(req):
>> req.write("Hello World!")
>> return apache.OK
>>
>> Frankly, I don't understand what is going on in the above. This is a bit
>> different compared to what I am used to.
>>
>> So, my question, would you all please point me to some introductory
>> resources, tutorials, books, that focus on Python programming for the web?
>> I
>> am eventually going to interface with some web services, notably Amazon
>> Web
>> Services. Also, I'd like to write some server side scripts to serve as a
>> backend to some Adobe AIR apps.
>>
>> Any and all advice is extremely appreciated.
>>
>> Thanks for your time!
>>
>> Sincerely,
>>
>> Jason
>>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Leaving PHP for Python

2008-11-25 Thread Don Jennings
Welcome! I suggest you take a look at django [1]. You'll find that it
has documentation [2] and an active developer community [3]. Of
course, for your questions about learning python, you've already found
a very helpful community : >)

Take care,
Don

[1]  http://www.djangoproject.com/
[2] http://docs.djangoproject.com/en/dev/
[3] http://www.djangoproject.com/community/

On 11/25/08, Jason DeBord <[EMAIL PROTECTED]> wrote:
> Hello All,
>
> This is my first message on the mailing list. I am excited to get started
> developing content / backend for the web with Python.
>
> I have a background in PHP, but am convinced that Python is a better, more
> powerful language.
>
> I am on a Windows XP machine and I have been using XAMPP for server, php,
> mysql...
>
> I installed Python 2.5 and mod_python successfully. I can serve pages with
> .py extension to http://localhost .
>
> The following for example:
>
> from mod_python import apache
>
> def handler(req):
> req.write("Hello World!")
> return apache.OK
>
> Frankly, I don't understand what is going on in the above. This is a bit
> different compared to what I am used to.
>
> So, my question, would you all please point me to some introductory
> resources, tutorials, books, that focus on Python programming for the web? I
> am eventually going to interface with some web services, notably Amazon Web
> Services. Also, I'd like to write some server side scripts to serve as a
> backend to some Adobe AIR apps.
>
> Any and all advice is extremely appreciated.
>
> Thanks for your time!
>
> Sincerely,
>
> Jason
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Converting a string into dictionary references

2012-04-23 Thread Don Jennings
Remember, the keys for the dictionary in your example are simply strings. It 
just so happens that those strings are in another file. Read the file which 
contains the specified columns and split on the comma into variable names for 
your output:


with open(spec_file, 'r') as f:
outcol1, outcol2, outcol3 = f.readline().split(',')

# use variable names to access dictionary
print row[outcol1] + ',' + row[outcol2] + ',' + row[outcol3]


Now, if you are unsure how many columns will be in the file with specified 
columns, that changes things slightly:


# get a list of the requested columns
outcols = []
with open(spec_file, 'r') as f:
line = f.readline()
outcols.extend(line.split(','))

# later, use that list to do something with the output (I assume strings for 
your data here)
print ','.join([row[outcol] for outcol in outcols])

Helpful?

Take care,
Don


> Not quite,
> 
> I have csvfile1:
> column1, column2, column3, ... column200
> 
> That is my raw data but I want to use only 5 columns for example in a
> specific application.
> I thus want a file with the following:
> column33,column1,column5
> 
> I then want to read the original csv file and write a new csv file with the
> requested columns only.
> 
> Does that make more sense?
> 
> Regards
> 
> On 23 April 2012 14:41, Joel Goldstick  wrote:
> 
>> On Mon, Apr 23, 2012 at 8:56 AM, Gerhardus Geldenhuis
>>  wrote:
>>> Hi
>>> Appologies about the subject I could not think of a better description.
>>> 
>>> I have this very simple function:
>>> 
>>> def readcsvfile(filename):
>>>  f = open(filename, 'ro')
>>>  csvdata = csv.DictReader(f)
>>>  for row in csvdata:
>>>print row["column3"]+','+row["column1"]
>>> 
>>> I have another inputfile that will be comma separated list of values.
>>> Eg:
>>> column3,column4,column10
>>> 
>>> The idea is that I use this inputfile to tranform the original csv file.
>> I
>>> thus want a new file with only the specified columns. I am sure there is
>> an
>>> elegant way of doing this but I am not sure how to convert my print
>>> statement into something more dynamic. Any pointers would be appreciated.
>>> 
>>> Regards
>>> 
>>> --
>>> Gerhardus Geldenhuis
>>> 
>>> ___
>>> Tutor maillist  -  Tutor@python.org
>>> To unsubscribe or change subscription options:
>>> http://mail.python.org/mailman/listinfo/tutor
>>> 
>> 
>> So you want to take 'column1' and get back 1?, 'column10' and get back 10?
>> 
>> s = 'column1'
>> i = int(s[6:])
>> 
>> This will only work if your strings all start with the text 'column'
>> 
>> --
>> Joel Goldstick
>> 
> 
> 
> 
> -- 
> Gerhardus Geldenhuis
> -- next part --
> An HTML attachment was scrubbed...
> URL: 
> 
> 
> --
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 
> End of Tutor Digest, Vol 98, Issue 58
> *

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


Re: [Tutor] Looping over histogram plots

2012-06-26 Thread Don Jennings
> Message: 1
> Date: Tue, 26 Jun 2012 18:40:50 +1000
> From: Elaina Ann Hyde 
> To: tutor@python.org
> Subject: [Tutor] Looping over histogram plots



>set=(dat['a'+str(index)] == 1.00)

You should not override the builtin set() type [1] as you've done here by 
assigning it.

> #write the data
>P.hist(VGSR[set],bins=30, normed=True)

I am not familiar with matplotlib, etc. but given that the primary difference 
in your two code samples is where you write the data, I suspect you want 
something like:

ax.plot(P.hist(VGSR[set],bins=30, normed=True))

Take care,
Don

[1] http://docs.python.org/library/stdtypes.html#set
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] advice on global variables

2012-07-11 Thread Don Jennings

On Jul 11, 2012, at 4:48 AM, tutor-requ...@python.org wrote:

> Message: 1
> Date: Tue, 10 Jul 2012 19:31:09 -0500
> From: Chris Hare 
> To: tutor@python.org
> Subject: Re: [Tutor] advice on global variables
> Message-ID: <38ebadce-c2b1-4f15-b6e1-cb725f800...@labr.net>
> Content-Type: text/plain; charset=windows-1252
> 
> 
> On Jul 10, 2012, at 6:24 PM, Alan Gauld wrote:
> 
>> On 11/07/12 00:16, Alan Gauld wrote:
>> 
 One thought was a RAM based SQLite database, but that seems
 like a lot of work.  I dunno, maybe that is the option.
>>> 
>>> is definitely the best option where the "global" needs to be shared
>>> across different programs as well as different modules in a single
>> 
>> I meant to add its also the right technique where the 'global' value has to 
>> persist between different execution cycles of the program. (Or indeed any 
>> kind of value needs to persist across execution cycles!)
>> 
> 
> Thanks Alan -- I am thinking I am just gonna go with the RAM based SQLite 
> database ?. 

Another option you might want to consider is the y_serial module [1] as it's a 
lot less work and allows you to **keep** thinking in python :>)

Take care,
Don

[1] http://yserial.sourceforge.net/

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


Re: [Tutor] get columns from txt file

2012-07-11 Thread Don Jennings

On Jul 11, 2012, at 10:21 AM, tutor-requ...@python.org wrote:
> 
> Message: 4
> Date: Wed, 11 Jul 2012 16:20:05 +0200
> From: susana moreno colomer 
> To: 
> Subject: [Tutor] get columns from txt file
> Message-ID: 
> Content-Type: text/plain; charset="iso-8859-1"
> 
> 
> Hi!
> 
> I have a group of files in a directory.
> I want to extract from  files whose names start with  bb_   column number 5 
> to an excel file. I have 6  bb_  files, therefore I want to get 6 columns 
> (5th column from each file)
> This code is working,with the following errors:
> 
> I get the data in only one column, instead of six
> I get white cell after every extracted cell
> 
> I've got  help from 
> http://mail.python.org/pipermail/tutor/2004-November/033474.html, though it 
> is not working for me


If I understand your requirements correctly, you should read the followup 
message in that thread:

http://mail.python.org/pipermail/tutor/2004-November/033475.html

Primarily, you'll just have to alter one of the code samples to write it to csv.

Take care,
Don

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


Re: [Tutor] get columns from txt file

2012-07-12 Thread Don Jennings
(Please use reply all so the message gets posted for all to see :>)

On Jul 12, 2012, at 7:14 AM, susana moreno colomer wrote:

> Hi!
> Many thanks for your help.
> Now I am trying this, but I get a blank excel document

Not surprising as there are several errors in your code. In fact, I'm surprised 
it ran without reporting an error. Be sure to copy and paste the code exactly 
as you are running it.

> (I have tried everything, but I don't get it!)

That's why we're here :>)

As I understand it, you have a file structure like this:

dir/
bb_csvfile1.txt
bb_csvfile2.txt
bb_csvfilen.txt
someotherfile.txt

You want to read each of the csv files which start with 'bb_', extracting the 
data in a certain column, and then output that data to a single excel document. 
Yes?


>  
> import os
> import fnmatch
> import csv
> 
> path = '...'

First of all, this path variable looks odd. Do you mean '.' for the current 
directory or '..' for the parent directory?

> csv_out=csv.writer(open('out11.csv', 'wb'), delimiter='  ')

Since you said you want an excel document, you should specify dialect='excel'  
(or 'excel-tab') instead of a delimiter.

> files=os.listdir(path)
>  
> for infile in files:
>  output=[] 

The variable output should be moved outside the for loop (i.e. put it before 
the "for infile in files:")

>  if fnmatch.fnmatch(infile, 'bb_*'):
>   global filename

Drop the global statement. Out of curiousity, why did you think you needed 
that? (There was no use of global in the example code from Kent Johnson.)

>   filename= path+infile

Won't work (even if the path variable was correct)—where's the file path 
separator? Use the join function of os.path:

filename = os.path.join(path, infile)

> 
>   global f

Again, no need for the global statement.

>   f=open(filename, 'r')
>
>   for line in f:
>  
>b=line.split('\t')
>output.append(b[5].strip())
>   
>def csvwriter():

No need for a function here. In fact, you don't ever actually call it, so it 
never gets run! That's a major reason why you aren't getting any output.

> csv_out.append(output)
> csv_out.append('\n')

These should be outside of the for loops as well (i.e. remove all indentation).
>
>   f.close


You need the parentheses to call the function and it should be at the same 
level as the call where you open it (i.e. the same amount of indentation, 
before the calls to csv_out.append):

f.close()

Take care,
Don

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


Re: [Tutor] get columns from txt file

2012-07-12 Thread Don Jennings
Oops! Still you forgot to cc: the tutor list. It's really important because if 
someone (like me, for instance) steers you in the wrong direction, others will 
jump in with corrections.


On Jul 12, 2012, at 9:48 AM, susana moreno colomer wrote:

> Hi!
> Many thanks!

You're welcome. I see that your code is improving :>)

> Still I get an error: AttributeError: '_cvs.writer' object has no atribute 
> 'append'.

If you would like a response to that error, please send the exact code you 
tried which didn't work and the error message by copying/pasting. (See, I'm 
pretty sure that you typed in the error above since you misspelled attribute as 
'atribute'.)

> I wanted to solve it with the Def function.

And that's why you should send the original code and error. Now, you have a 
different problem, but it's a good time to clear up your confusion. Def is not 
a function. In fact, I don't know what "Def" is. Instead, the def 
statement—notice that it's all lower case—defines a function which you can call 
elsewhere in code.

>>> def call_me():
... print "inside the call_me function"
... 
>>> call_me()
inside the call_me function

Note, that there is no output from our defining the call_me function; it's only 
when we call it with the parentheses that the code inside of it is executed. 
Make sense? However, again, it's not necessary for this script. Once you have 
the csv_out variable, you should be able to 

> Now I am trying this, though I get
>  
>  
> >import os
> >import fnmatch
> >import csv
> 
> >path = '/This is my current directory/'
> >csv_out=csv.writer(open('out13.csv', 'wb'), delimiter=' ')
> >files=os.listdir(path)
> >outfile=open('myfile1', 'w')
> >output=[]
> 
> >for infile in files:
> >  if fnmatch.fnmatch(infile, 'bb_*'):
> >  filename= os.path.join(path,infile)
> >  f=open(filename, 'r')
>   
> >  for line in f:
> >  b=line.split('\t')
> >  output.append(b[5].strip())
> > f.close()
>  
> >Def csvwriter():   >gives me SyntaxError: invalid syntax
> >excelfile=csv_out
> >a=excelfile.append(output)
> >c=excelfile.write(a)
> >return c
>  
>  
> I am trying with this  because the atribute 'writerows' didn't work.

A different error. There are lots of reasons it might not have worked. Wish you 
had sent us the code for that one :<( We can't solve it without all the info.

> Is there another way to write in csv files?

Absolutely. At the interactive prompt, dir() shows all the attributes of an 
object to find out your options:

>>> csv_out=csv.writer(open('out13.csv', 'wb'), dialect='excel')
>>> dir(csv_out)
['__class__', '__delattr__', '__doc__', '__format__', '__getattribute__', 
'__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', 
'__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'dialect', 
'writerow', 'writerows']

See the writerow and writerows? Those look promising. Alternatively, while it 
takes a while to learn to read the python documentation, it really is your 
friend:

http://docs.python.org/library/csv.html

If you'd like further examples, Doug Hellman often provides a great resource 
with his Python Module of the Week (PYMTOW) series:

http://www.doughellmann.com/PyMOTW/csv/

> I don't know what you mean with specify dialect

Something like this:

csv_out = csv.writer(fileobject, dialect='excel')

Take care,
Don

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


Re: [Tutor] get columns from txt file

2012-07-12 Thread Don Jennings

On Jul 12, 2012, at 10:55 AM, susana moreno colomer wrote:

> Hi!
>  
> I have a group of files in a directory:
> bb_1.txt
> bb_2.txt
> bb_3.txt
> bb_4.txt
> bb_5.txt
> bb_6.txt
> ss_1.txt
> 
> I want to extract from  files whose names start with  bb_   column number 5 
> to an excel file. I have 6  bb_  files, therefore I want to get 6 columns 
> (5th column from each file)
> This code is working,with the following errors:
> 
> I get the data in only one column, instead of six

Great! It sounds like you're almost there. Where's the code which works except 
that it puts the data all in one column?

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


Re: [Tutor] get columns from txt file

2012-07-12 Thread Don Jennings

On Jul 12, 2012, at 11:10 AM, susana moreno colomer wrote:

> Hi!
> It is attached on the email, called myprogram.txt

and, here are the contents of that file:

> #! /usr/bin/env python
> 
> 
> import os
> import fnmatch
> import csv
> 
> 
> path = '//../my_working_folder/'
> csv_out=csv.writer(open('out14.csv', 'wb'), delimiter=' ')
> files=os.listdir(path)
> 
> outfile=open('myfile1', 'w')

Here you've opened a file called "outfile" which you never use! So, of course 
it's blank. Just remove this line.

> output=[]
> 
> 
> for infile in files:
  columnData = []
>   if fnmatch.fnmatch(infile, 'bb_*'):
>   filename= os.path.join(path,infile)
>   f=open(filename, 'r')
>   
>   for line in f:
>   
>   b=line.split('\t')
  # remove the next line
>   output.append(b[5].strip())
  # instead, append to columnData list
  columnData.append(b[5].strip())
>   f.close()

  # now append all of that data as a list to the output
  output.append(columnData)

  # now, as Kent said, create "a list of row lists from the list of column lists
  # if any of the column lists are too short they will be padded with None"

  rows = map(None, *output)

  # now, write those rows to your file
  csv_out.writerows(rows)

> 
> This gives me a single column (I want 6, since I have 6 bb_files:
> 
> csv_out.writerows(output)

One of the things you missed in Kent's code is that the output is a list of 
lists. So, for each file you need a list which you then append to the output 
list. I've inserted the appropriate code above and you should have better luck 
if you copy and paste carefully.

> 
> 
> with this I get excel whitesheet
> 
> 
> def csvwriter():  
>   excelfile=csv_out
>   a=excelfile.append(output)
>   c=excelfile.write(a)
>   return c

Right! As I explained in an earlier email, you never call the function 
csvwriter; you merely define it. The file is created when you opened it earlier 
for writing on line 10 of your program, but you never write anything to it.

If you have the time and inclination, I recommend you work through one of the 
fine tutorials for python. It really is a great language and this is a 
**great** community of folks for people like me who are learning the language 
still.

Take care,
Don



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


Re: [Tutor] get columns from txt file

2012-07-12 Thread Don Jennings

On Jul 12, 2012, at 12:06 PM, susana moreno colomer wrote:

> 
> Hi!
> This code is working fine!
> The only one little thing is that the 6 columns appear together in one 
> column, what means, in eac cell I get 6 numbers. How can I get tit in 6 excel 
> columns?

Programming is hard, so don't feel bad that I'm having to tell you again to 
specify the dialect as "excel" or "excel-tab":

csv_out=csv.writer(open('out14.csv', 'wb'), dialect='excel')

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


Re: [Tutor] finally without try or except

2012-07-31 Thread Don Jennings

On Jul 31, 2012, at 12:26 PM, tutor-requ...@python.org wrote:

> Message: 2
> Date: Tue, 31 Jul 2012 10:44:29 -0400
> From: Tino Dai 
> To: "Steven D'Aprano" 
> Cc: "tutor@python.org" 
> Subject: Re: [Tutor] finally without try or except
> Message-ID:
>   
> Content-Type: text/plain; charset="iso-8859-1"
> 
> On Mon, Jul 30, 2012 at 9:01 PM, Steven D'Aprano wrote:
> 
>> If you want to be robust, it is best not to try to beat the database. That
>> means you should write to the database as soon as you can, as often as you
>> need to, and let the database do what it does best: reliable transaction
>> storage. Any decent database will guarantee ACID compliance (atomicity,
>> consistency, isolation, durability).
>> 
> 
>> But sometimes you need to compromise on robustness for speed or
>> convenience.
>> 
>> 
>> [...]
>> 
>> This is how the program was originally structured, but we found
>>> performance
>>> problems with in.
>>> It's using Django and an Oracle DB, which is notoriously bad for single
>>> record read/writes. So, I
>>> figured why don't we append them all to an array, and write them out at
>>> the
>>> end of the program.
>>> 
>> 
>> I suggest you periodically check the item log, and if there are more than
>> (say) 20 items, you write them to the database and clear the temporary
>> list. That way, the number of item logs should never get too large, and the
>> performance shouldn't suffer too greatly. You will need to tweak that
>> number to be more or less depending on how poorly the Oracle DB performs.
>> 
>> Then, at the very end of the program, you write whatever items are left in
>> a finally clause, or atexit. That way, the finally clause should be nice
>> and speedy and the user is unlikely to hit Ctrl-C a second time.
>> 
>> 
> I think that is the process I'm going to take. It doesn't seem as elegant,
> but I think it's a good compromise.


Another option might be to write each item to a different database which has 
better performance for single record writes—and, I'm betting someone on this 
list will have an excellent recommendation for such a DB. Then, you could batch 
the updates to the Oracle DB independently of the main program (the one related 
to your question).

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


[Tutor] better tools

2012-08-22 Thread Don Jennings
[slightly OT]

After watching Bret Victor's talk[1], I want **much** better tools for 
programming (and all of the other stuff I do on the computer).

John Resig, creator of jQuery,  claims[2] that Victor's presentation inspired 
the new platform for learning javascript at Khan Academy[3]. I plan to try it 
out.

Take care,
Don

[1] http://vimeo.com/36579366

[2] http://ejohn.org/blog/introducing-khan-cs/

[3] http://www.khanacademy.org/cs
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] 2.7.3 Popen argument issues

2012-08-26 Thread Don Jennings

On Aug 26, 2012, at 12:25 AM, tutor-requ...@python.org wrote:

> Message: 2
> Date: Sat, 25 Aug 2012 17:46:08 -0700
> From: Ray Jones 
> To: tutor@python.org
> Subject: [Tutor] 2.7.3 Popen argument issues
> Message-ID: <503971d0.5040...@gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
> 
> Is there a method by which I can get an exact representation of command
> line arguments passed by Popen as seen by the called program? The
> argument error I receive shows me an argument that looks exactly like
> the argument that I use with Bash (it should - I copied and pasted it) -
> but the Bash version works while the Python version doesn't.
> 
> The purpose is to capture http streaming video to a file and also split
> it out to a local port so that I can pop in and monitor where I am in
> the stream.
> 
> Here is my Bash call to vlc (it works):
> 
> vlc http://"$HOST":$PORT -I dummy --sout 
> '#duplicate{dst="transcode{vb=400}:std{access=file,mux=avi,dst=testing.avi}",dst="std{access=http,mux=mpjpeg,dst=127.0.0.1:11300}"}'

Notice that the above call ends in a single quote?

> &
> 
> Here is my Python call to vlc (error response to follow):
> 
> vlcExec = sp.Popen(['vlc', 'http://' + ip + ':' + port, '-I dummy',
> '--sout
> \'#duplicate{dst="transcode{vb=400}:std{access=file,mux=avi,dst=outFile
> + '.avi}",dst="std{access=http,mux=mpjpeg,dst=127.0.0.1:11300}"}\''])
> 
> (That is not an escaped double quote at the end - that is " \' " and " ' ").
> 
> Here is the resulting error from vlc:
> 
> vlc: unknown option or missing mandatory argument `--sout
> '#duplicate{dst="transcode{vb=400}:std{access=file,mux=avi,dst=testing.avi}",dst="std{access=http,mux=mpjpeg,dst=127.0.0.1:11300}"}''

Notice that this one ends in a double quote? Those are **definitely not** the 
same :>)

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


Re: [Tutor] Tutor Digest, Vol 102, Issue 98

2012-08-30 Thread Don Jennings

On Aug 30, 2012, at 8:15 PM, tutor-requ...@python.org wrote:

> Message: 6
> Date: Fri, 31 Aug 2012 00:15:41 +
> From: Ashley Fowler 
> To: "tutor@python.org" 
> Subject: [Tutor] Printing a list as a column
> Message-ID:
>   
> <6962c976ae76ac4298cbf6fd6d0c63561f37c...@bl2prd0710mb363.namprd07.prod.outlook.com>
>   
> Content-Type: text/plain; charset="iso-8859-1"
> 
> Does anyone know how to print a list in a form of a column instead of a row?

Please give an example of what you mean here. For example, you might want to 
see:

['a',
 'b',
 'c',
 'd',
 'e']

My guess is that what you want is for the list ['a', 'b', 'c', 'd', 'e'] to 
print out as:

a
b
c
d
e

Yes? Are you familiar with the join method of strings? Try it out. If you have 
trouble, let us know :>)

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


[Tutor] find('') returns 0

2012-09-16 Thread Don Jennings
This behavior seems strange to me:  the find method of a string returns the 
position zero when you search for an empty string (granted, I can't quite 
figure out why you'd search for an empty string, either).

>>> 'abc'.find('')
0

Anyone care to share a good explantion for this behavior and possible use 
cases? Thanks!

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


Re: [Tutor] For - if - else loop; print selective output

2012-10-24 Thread Don Jennings

On Oct 24, 2012, at 12:27 PM, tutor-requ...@python.org wrote:

> Hi,
> 
> a = [['jimmy', '25', 'pancakes'], ['tom', '23', 'brownies'], ['harry',
> '21', 'cookies']]
> for i in a:
>if (i[1] == '25' or i[1] == '26'):
>print 'yes'
> else:
>print 'Not found'

Suggestion:  use names which are meaningful.

> 
> This prints:
> yes
> not found

I'd be very surprised by that. What it should print is:
yes
Not found

(Note the capital letter at the beginning of the last line.)

> 
> I want it to print "yes" for each positive match but nothing for a negative
> match. However if all matches are negative, I want it to print "Not found"
> once (That bit the code already does).

Yes, it prints that text, but do you understand why it does? It's not because 
two of the items do not match your if statement.

> I do I get it to print "yes" only in
> a mix result situation?

While there are lots of ways to approach this exercise, I suggest that you try 
this:  first, go through the list as you are doing now, checking if any of the 
items (are these ages, perhaps?) are a "positive match", appending a "yes" to 
another list (do you know how to create an empty list and append to it?). Then, 
if that list is not empty, you'll print 'yes' for every item, else you'll print 
the "Not found" once. For the latter, here is some code to get you started:

people = ['Sally', 'Bob']

if people:
print "this list contains something"
else:
print "this list is empty"

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


Re: [Tutor] Tutor Digest, Vol 105, Issue 55

2012-11-21 Thread Don Jennings

On Nov 21, 2012, at 5:57 AM, tutor-requ...@python.org wrote:

> On Wed, Nov 21, 2012 at 3:53 PM, Timo  wrote:
> 
> 
> I can create a torrent using py3createtorrent locally, but am unable to
> figure how it will work via a django web app.
> 
> To make it work locally, i specified the local location of the folder, i
> wanted to create a torrent for.
> 
> In the web app scenario, the user selects the content present on the user's
> local machine,
> after that, how do i use py3createtorrent to create a torrent on the server
> end, since the content is not present on the server .

I am pretty sure you've answered your own question:  the content has to be on 
the server. Basically, after the user selects the content on their local 
machine, upload it to the server, then process it from there.

Take care,
Don

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


[Tutor] MIT python video [WAS: Re: Hi Don,]

2012-11-22 Thread Don Jennings

On Nov 22, 2012, at 8:11 AM, Waters, Mike [ITSCA Non-J&J] wrote:

> Hi Don, first thanks for the support on Python, I find the information very 
> helpful.

You're welcome. You'll find it even more helpful if you send your questions to 
the whole python tutor list which I've cc'd :>)

> I have been watching the MIT John Gutag and he will highlight a section of 
> code and then go to the” Format “tab and pick something about the 3 or 4 th 
> line down to remove the data.

I have not seen these videos, so I can only guess he's using some kind of IDE 
perhaps? IDLE maybe?

> Why do I not have a Format button?(I am running 2.7 on Win) And since the 
> image is not clear on the screen what is he doing?

You'll be happy to find out that the slides are available in pdf format. Go to 
the main page for the course [1] and choose one of the units in the navigation 
sidebar on the left. Then you'll see the list of topics. After clicking on one 
of those, you should find the "Lecture slides" under the "Session Activities" 
section of the page.

Take care,
Don


[1] 
http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00sc-introduction-to-computer-science-and-programming-spring-2011/Syllabus/




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


Re: [Tutor] MIT python video [WAS: Re: Hi Don,]

2012-11-23 Thread Don Jennings

On Nov 22, 2012, at 9:48 PM, Jan Karel Schreuder wrote:

> 
> 
> On Nov 22, 2012, at 5:47 PM, Don Jennings  wrote:
> 
>> 
>> On Nov 22, 2012, at 8:11 AM, Waters, Mike [ITSCA Non-J&J] wrote:
>> 
>>> Hi Don, first thanks for the support on Python, I find the information very 
>>> helpful.
>> 
>> You're welcome. You'll find it even more helpful if you send your questions 
>> to the whole python tutor list which I've cc'd :>)
>> 
>>> I have been watching the MIT John Gutag and he will highlight a section of 
>>> code and then go to the” Format “tab and pick something about the 3 or 4 th 
>>> line down to remove the data.
>> 
>> I have not seen these videos, so I can only guess he's using some kind of 
>> IDE perhaps? IDLE maybe?
>> 
>>> Why do I not have a Format button?(I am running 2.7 on Win) And since the 
>>> image is not clear on the screen what is he doing?
>> 
> 
> Gutag uses Idle 

Thanks! In case it helps future http://duckduckgo.com searchers, the name is 
actually "Guttag".

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


[Tutor] reading web page with BeautifulSoup

2012-12-12 Thread Don Jennings

On Dec 12, 2012, at 8:54 PM, tutor-requ...@python.org wrote:

> Date: Wed, 12 Dec 2012 20:47:58 -0500
> From: Ed Owens 
> To: tutor@python.org
> Subject: [Tutor] reading web page with BeautifulSoup
> Message-ID: <50c933ce.5010...@gmx.com>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
> 
 from urllib2 import urlopen
 page = urlopen('w1.weather.gov/obhistory/KDCA.html')
> Traceback (most recent call last):
>   File "", line 1, in 
>   File 
> "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py",
>  
> line 126, in urlopen
> return _opener.open(url, data, timeout)
>   File 
> "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py",
>  
> line 386, in open
> protocol = req.get_type()
>   File 
> "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py",
>  
> line 248, in get_type
> raise ValueError, "unknown url type: %s" % self.__original
> ValueError: unknown url type: w1.weather.gov/obhistory/KDCA.html
 
> 
> Can anyone see what I'm doing wrong here? 

Yes, you should pass the full url, including the scheme:

urlopen('http://w1.weather.gov/obhistory/KDCA.html')

By the way, your subject line would be better if it had something to do with 
url, as the problem is completely unrelated to BeautifulSoup :>)

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


Re: [Tutor] Python gmail script for conky

2013-01-20 Thread Don Jennings

On Jan 19, 2013, at 8:15 PM, tutor-requ...@python.org wrote:

> Date: Sat, 19 Jan 2013 18:27:46 -0500
> From: Polo Heysquierdo 
> To: Tutor@python.org
> Subject: [Tutor] Python gmail script for conky
> Message-ID:
>   
> Content-Type: text/plain; charset="iso-8859-1"
> 
> I'm getting the following error on my script for conky.
> 
> "Traceback (most recent call last):
>  File "/home/troll/.gmail/gmail.py", line 1, in 
>import urllib.request
> ImportError: No module named request"

(Probably someone will beat me to the punch since I get the digest of this 
list, still…)

Most likely, you are using python 2 to run python 3 code as the urllib.request 
is available in python 3 (see note at top of this page [1]).

Take care,
Don

[1] http://docs.python.org/2/library/urllib.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutor Digest, Vol 108, Issue 75

2013-02-22 Thread Don Jennings

On Feb 22, 2013, at 9:12 PM, tutor-requ...@python.org wrote:

> Message: 5
> Date: Fri, 22 Feb 2013 21:03:00 -0500
> From: Dave Angel 
> To: tutor@python.org
> Subject: Re: [Tutor] How to break long lines?
> Message-ID: <51282354.3030...@davea.name>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
> 
> On 02/22/2013 08:22 PM, Jim Byrnes wrote:
>> 
>>>  
>>> 
>> 
>> Thanks for giving me so many options to use in the future.  When reading
>> I completely blew by the single quote on a single line part.  The db is
>> sqlite3 and it seems happy with ''' strings.
>> 
> 
> FWIW, there is absolutely no difference between a string object created 
> with single quotes, one created with triple-quotes, or one created by 
> calling some function, or by evaluating some expression.

I beg to differ as it's bitten me on more than one occasion. As Steve pointed 
out, the triple quoted option embeds newlines. Maybe you mean something 
different than what I take your statement to mean?

Take care,
Don

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


Re: [Tutor] A CSV field is a list of integers - how to read it as such?

2013-03-03 Thread Don Jennings

On Mar 3, 2013, at 9:24 PM, DoanVietTrungAtGmail wrote:

> Dear tutors
> 
> I am checking out csv as a possible data structure for my records. In each 
> record, some fields are an integer and some are a list of integers of 
> variable length. I use csv.DictWriter to write data. When reading out using 
> csv.DictReader, each row is read as a string, per the csv module's standard 
> behaviour. To get these columns as lists of integers, I can think of only a 
> multi-step process: first, remove the brackets enclosing the string; second, 
> split the string into a list containing substrings; third, convert  each 
> substring into an integer. This process seems inelegant. Is there a better 
> way to get integers and lists of integers from a csv file?

A quick search for "python list object from string representation of list" 
returned an idea from stackoverflow which I have adapted for integers:

>>> import ast
>>> num_string = "[1, 2, 3]"
>>> ast.literal_eval(num_string)
[1, 2, 3]


Take care,
Don

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


Re: [Tutor] argparse iterable

2013-04-01 Thread Don Jennings

On Apr 1, 2013, at 8:31 PM,   wrote:

> 
> 
> print("But this doesn't iter through a b and c:")
> for k,v in parser.parse_args():
>print('This arg is %s %s' % k, k[str(v)])
> $ 
> -
> 
> My error:
> $ h.py -a -b hi -c 42
> Namespace(a=True, b='hi', c=42)
> But this doesn't iter through a b and c:
> Traceback (most recent call last):
>  File "./h.py", line 16, in 
>for k,v in parser.parse_args():
> TypeError: 'Namespace' object is not iterable
> $ 
> 
> How can I get parser to be iterable?

Jason, Mark and Dave have addressed this part of your question already.

> 
> After I get it to iter, I suppose that I'll be bitten by the boolean and 
> integer
> type conversions. I'm not sure how to handle that either. Will 'str()' save 
> me?

What do you mean here? You're thinking that you have to convert them to strings 
before passing them to the print function? Actually, the string formatting 
operator, the percent sign, combined with the 's' will convert for you, using 
the str() method. So, the code above is redundant. Just use:

print('This arg is %s %s' % k, v)

Take care,
Don

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


Re: [Tutor] FYI: An Introduction to Interactive Programming in Python

2013-04-08 Thread Don Jennings

On Apr 8, 2013, at 7:58 PM, Steven D'Aprano wrote:

> On 09/04/13 06:38, brian arb wrote:
>> An Introduction to Interactive Programming in PythonJoe Warren, Scott
>> Rixner, Stephen Wong and John Greiner
>> 
>> This course is designed to be a fun introduction to the basics of
>> programming in Python. Our main focus will be on building simple
>> interactive games such as Pong, Blackjack and Asteroids.
>> 
>> https://www.coursera.org/course/interactivepython
> 
> Thanks for the link Brian.
> 
> As an aside, I wonder, apart from Conway's Game of Life, which isn't
> actually a game at all, what's a non-interactive game?

Watching someone else play Pong? ;>)

Take care,
Don

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


Re: [Tutor] building a website with python

2013-04-09 Thread Don Jennings

On Apr 9, 2013, at 5:31 PM, Benjamin Fishbein wrote:

> Hello. I learned Python this past year (with help from many of you) and wrote 
> many programs for my small business. Now I want to build a website. I 
> acquired the domain name through godaddy.com (bookchicken.com) but have not 
> found hosting yet.
> I learned html, css, and javascript via codeacademy.org, but have never built 
> a website.
> I would like to build it with Python,

So, are you really just wanting to use python to build a static site? If so, 
you can run a python web framework on your local machine and then deploy the 
static files to any decent host you find. For example, there are instructions 
for setting up this scenario using flask, jinja2 and markdown[1]. If you have 
experience with ReStructuredText (here's a comparison of the two markups [2]), 
it's fairly easy to use docutils to produce the html files.
 
> and was wondering if you could give me some pointers about what I need to 
> learn first: Django is the thing to use? And do I need specific hosting to 
> use python or are all hosts basically the same.

If you do want python web apps, I've had pleasant results from webfaction.com 
(though I don't do anything terribly difficult :>).

You've gotten some good feedback, but I suspect you will get better information 
if you provide more information about your goals for the site.

Take care,
Don

[1] 
https://nicolas.perriault.net/code/2012/dead-easy-yet-powerful-static-website-generator-with-flask/
[2] http://www.unexpected-vortices.com/doc-notes/markdown-and-rest-compared.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] building a website with python

2013-04-10 Thread Don Jennings

On Apr 9, 2013, at 11:07 PM, Benjamin Fishbein wrote:

>> 
>> You've gotten some good feedback, but I suspect you will get better 
>> information if you provide more information about your goals for the site.
>> 
> 
> Thanks for your help, everyone. There are some specific things I want the 
> site to do, and I'm not sure which would be the best developing tool or 
> hosting for these.
> The python software I developed is for selling used books.
> It takes book ISBN numbers as input and returns the best prices being offered.
> It uses the selenium module...I'm not sure how that would translate into a 
> website.

Checking the documentation [1], selenium will interact with a browser running 
remotely using the selenium-server. However, I don't imagine the latter option 
being viable if you plan to have any significant traffic. I would think a 
better plan is to forego the gui browser, perhaps re-writing the interaction 
with other sites using requests [2], a very nice way to work with HTTP. Do you 
need to interact with javascript on those pages?

> There are many websites that offer similar book price comparisons, but mine 
> is different...it's user-friendly. Any volunteer at a thrift shop or library 
> can use it...just a series of simple directions and yes/no questions, taking 
> the user all the way from scanning or typing in an ISBN to dropping the 
> parcel off at the post office. (The local libraries I worked with more than 
> doubled their used-book revenues.) I want to expand this nationwide, and 
> bookchicken.com seems to be the way to do it.
> So much of the program is simple enough. But there's two parts of the program 
> that I anticipate being important to what host, development tool I use:
> 1. ISBNs (the books the thrift shop/ library has) being sent to various 
> websites and returning the data to my site to be analyzed by my program.
> 2. Maneuvering through the website of the company buying the books. I don't 
> want to send the user off to a warehouse's site with a list of books to sell 
> to them. They'll still be entering their address and name, but it'll be on my 
> site, that I then send to the warehouse's page, get a packing slip and 
> shipping label from the warehouse, and give these documents to the user to 
> print out.
> 
> I'm not sure if this changes anyone's ideas about which host/ developer I 
> should use. Please let me know.

Obviously my recommendations for producing a static site missed the mark! I do 
think that one of the microframeworks folks have mentioned will get you up and 
running faster.

Take care,
Don

[1] http://docs.seleniumhq.org/docs/03_webdriver.jsp
[2] http://docs.python-requests.org/en/latest/user/quickstart/
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] design question (Django?)

2013-04-14 Thread Don Jennings

On Apr 14, 2013, at 7:06 AM, Albert-Jan Roskam wrote:

> 
> 
>  > Subject: Re: [Tutor] design question (Django?)
>> 
>> On 13/04/13 09:48, Albert-Jan Roskam wrote:
>> 
>>> I think I have to make a diagram of this. This stuff is quite hard
>> 
>> You could use a simple UML class diagram (class -> table). See the OOP topic 
>> in my V3 tutorial for simple examples.
>> 
>> Or you could use a proper entity relationship diagram(ERD) - see wikipedia 
>> for 
>> details and examples (there are various notational variations)
>> 
>> They all show the same concepts. UML will be best if you plan
>> on using OOP in the python code. ERD is better for vanilla database design.
> 
> Hi Alan, I am reading it now. Thanks for the suggestion. I have to read more 
> about Django to decide whether this is the way to do it. First impression: 
> yes. The database abstraction API also implies that I should use OOP. Step 
> #1: defining the model ;-) 
> https://docs.djangoproject.com/en/dev/topics/db/models/
> Would it also be a good idea to simultaneously make a paper-and-pencil 
> drawing of the UI?

Absolutely! Test it with three users. See Jakob Nielsen's brief take on the 
matter:

http://www.nngroup.com/articles/paper-prototyping/

Take care,
Don

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


Re: [Tutor] oops - resending as plain text

2013-04-16 Thread Don Jennings

On Apr 16, 2013, at 1:48 PM, Jim Mooney wrote:

> I accidentally sent as HTML so this is a resend in case that choked
> the mailing prog ;')
> 
> I was doing a simple training prog to figure monetary change, and
> wanted to avoid computer inaccuracy by using only two-decimal input
> and not using division or mod where it would cause error. Yet, on a
> simple subtraction I got a decimal error instead of a two decimal
> result, as per below. What gives?
> 
> cost = float(input('How much did the item cost?: '))
> paid = float(input('How much did the customer give you?: '))
> change = paid - cost
> 
> #using 22.89 as cost and 248.76 as paid
> 
> twenties = int(change / 20)
> if twenties != 0:
>  twentiesAmount = 20 * twenties
>  change = change - twentiesAmount
>  #change is 5.8745, not 5.87 - how did I get this decimal
> error when simply subtracting an integer from what  should be a

Now that Joel Goldstick has pointed out the reason, you may wonder what to do 
now. Answer? Use the decimal module:

http://docs.python.org/2/library/decimal.html

Although, you might prefer Doug Hellmann's introduction:

http://pymotw.com/2/decimal/

Take care,
Don

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


Re: [Tutor] How to find reverse pair words in a list of Words that has to be accessed through a URL

2013-04-19 Thread Don Jennings

On Apr 19, 2013, at 4:56 PM, Chetan Sai wrote:

> Here is my question:
> 
> "Two words are a “reverse pair” if each is the reverse of the other. Write a 
> program that finds all the reverse pairs in the word list. The word list can 
> be downloaded athttp://www.puzzlers.org/pub/wordlists/pocket.txt";

Really, that's not a question, but we are happy to answer questions :>) Oh, 
there's your question in the subject line. What have you tried thus far? Have 
you given any thought to what steps you might have to take to solve this task?

Take care,
Don

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


Re: [Tutor] Why do I get an "unvalid syntax" on the print line for number1

2013-04-23 Thread Don Jennings

On Apr 23, 2013, at 2:19 PM, Chris “Kwpolska” Warrick wrote:

> On Sat, Apr 20, 2013 at 10:33 PM, Pat Collins  
> wrote:
>> Any help appreciated.
>> 
>> 
>> #!/usr/bin/env python
>> """
>> number.py Demonstrates collecting a number from the user.
>> """
>> 
>> number_string1 = float(input("Give me a number: "))
>> number1 = (number_string1)
>> 
>> number_string2 = float(input("Give me another number: "))
>> number2 = (number_string2)
>> 
>> print number1, "times", number, "+", number1 * number2
>> 
>> 
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>> 
> 
> You are probably using Python 3 (check with `python --version`).  In
> this version, print is a function.  You need to do the following
> instead:
> 
> print(number1, "times", number, "+", number1 * number2)

Once the OP fixes that error, I suspect another one will appear:

NameError: name 'number' is not defined

Take care,
Don

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


Re: [Tutor] Fwd: Re: Need Help Modifying a wxPython GUI (scrolling display and logging)

2013-06-14 Thread Don Jennings

On Jun 14, 2013, at 9:27 AM, Matt D wrote:

> im sorry i dont get it.  there is too many brackets in this lin:
> 
>   tmplist.append(field_values["nac"])
> 
> Thats where the error is but i dont see too many brackets?

Please don't top post.

The error is not on this line, but on the previous one. See below.
> 
> On 06/14/2013 08:56 AM, Flynn, Stephen (L & P - IT) wrote:
>> Not enough closing brackets on the previous line... or actually too many
>> opening brackets - you don't need all those that you have there already.
>> 
>> 
>>> #  tmplist = [time, 'nac', 'tgid', 'source', 'dest', 'algid'] is what
>> we
>>> want
>>>tmplist = []
>>>tmplist.append((str(strftime("%Y-%m-%d %H:%M:%S",
>> localtime(

Count the number of opening and closing parentheses. I count five opening ones, 
and only four closing. I believe the extraneous one is right before "str".

Take care,
Don

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


Re: [Tutor] i need help with the following question

2013-08-26 Thread Don Jennings

On Aug 26, 2013, at 4:29 AM, isaac Eric wrote:

> describe different ways of displaying output using python!

Well, that's not really a question now, is it? I would be happy to help, but 
which part of the task is confusing for you?

Take care,
Don

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


Re: [Tutor] i need help with the following question

2013-08-27 Thread Don Jennings

On Aug 27, 2013, at 3:40 AM, isaac Eric wrote:



> print "For a circle of radius %s the area is %s" % (radius,area)

> Question: What is the purpose of %s ?

Okay, so you're just getting started with python. We're happy to do some 
hand-holding, but we encourage you to think first.

You've followed the rest of the instructions and run the program? Don't worry 
about being precise with your answer to this question. Just try to express what 
you think is happening (we'll build on what you give us to make it clearer).

Take care,
Don

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


Re: [Tutor] XMLRPC question

2013-08-29 Thread Don Jennings

On Aug 29, 2013, at 3:37 AM, Ismar Sehic wrote:

> Hello, 
> I should write a python script(s) that listens to an existing XMLRPC service 
> on my company's dev server.

Yes, you should do that. Then, if you have problems, you should show some of 
your code to the fine tutors here, and they'll be happy to help you out :>)

> My utility should take some data from that XMLRPC, send it to an online xml 
> service provider(it's something about hotel accomodation, where they have xml 
> patterns for different requests), then they return their response to me, also 
> in xml data interchange format.then i should parse that and return to the 
> existing XML-RPC, or write the parsed data to the Posgresql database.The 
> thing is, i know something about XML parsing, i know also something about 
> XMLRPC,

That's good, but we have no idea what you know, unless you tell us.

> but i'm not permitted to edit the existing XMLRPC service.Can anyone just 
> tell me what is the shortest and the best solution for this problem, and give 
> me some guidelines for my project?

In answer to the question you asked, yes (but they'll probably want your 
paycheck ;>)

A quick search [1] yields a couple of promising articles [2] [3]. Including 
Doug Hellman's work in our search [4] provides another resource [5].

Take care,
Don

[1] https://duckduckgo.com/?q=python+xmlrpc
[2] http://www.ibm.com/developerworks/webservices/library/ws-pyth10/index.html
[3] http://www.xml.com/pub/r/1159
[4] https://duckduckgo.com/?q=python+xmlrpc+pymotw
[5] http://pymotw.com/2/xmlrpclib/
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python 2 & 3 and unittest

2013-09-04 Thread Don Jennings

On Sep 4, 2013, at 9:30 AM, Albert-Jan Roskam wrote:

> Hi,
> 
> I am trying to make my app work in Python 2.7 and Python 3.3 (one codebase) 
> and I might later also try to make it work on Python 2.6 and Python 3.2 (if I 
> am not too fed up with it ;-).

You might like to read Armin Ronacher's (Flask, Jinja2) take on this topic [1].

Take care,
Don

[1] http://lucumr.pocoo.org/2013/5/21/porting-to-python-3-redux/
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] cs student needs help import math

2013-09-07 Thread Don Jennings

On Sep 7, 2013, at 6:02 PM, Byron Ruffin wrote:


> 
> >>> math.ceil(math.pi)
> 4



> ... but I get the error when using ceil...
> 
> pepsticks = ceil(peplength / StickLength)
> Traceback (most recent call last):
>   File "", line 1, in 
> pepsticks = ceil(peplength / StickLength)
> NameError: name 'ceil' is not defined

Look carefully again at that error. Basically, it's telling you that 'ceil' is 
not the same as 'math.ceil' which is how you used it correctly the first time. 
That's an easy mistake to make.

Take care,
Don

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


Re: [Tutor] Copy and paste python on Microsoft word

2013-09-18 Thread Don Jennings

On Sep 18, 2013, at 12:59 AM, Sammy Cornet wrote:

> I'm using python 3.3.0, I have made a program on my script and output it. I 
> have tried several times to copy and paste the output and the script on 
> Microsoft word, every time I select the part that I need and right click on 
> it, this message appears: go to the file/line. It provides me no access to 
> copy and paste them. Please, can someone help me?

Evidently you are using an IDE which is interfering with the behavior you 
expect. Tell us which IDE and I bet someone will be able to point you in the 
right direction.

By the way, you *really* should use something other than MS Word to edit your 
python text files. People have offered plenty of suggestions in the past on 
this list. If you don't know how to search the archives (available at 
activestate [1] or gmane [2] among other places), ask.

Take care,
Don

[1] http://code.activestate.com/lists/python-tutor/
[2] http://news.gmane.org/gmane.comp.python.tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Two subsequent for loops in one function

2013-11-22 Thread Don Jennings

On Nov 22, 2013, at 9:24 AM, Rafael Knuth wrote:

> Hej there,
> 
> newbie question: I struggle to understand what exactly those two
> subsequent for loops in the program below do (Python 3.3.0):
> 
> for x in range(2, 10):
>for y in range(2, x):
>if x % y == 0:
>print(x, "equals", y, "*", x//y)
>break
>else:
>print(x, "is a prime number")

Let's step through the code. The outer for loop will iterate over the values of 
range(2, 10):

>>> range(2, 10)
[2, 3, 4, 5, 6, 7, 8, 9]

So, each time the loop executes, x will be one of the values in that list. The 
inner loop then checks to see if any values up to but not including that value 
are evenly divisible by it. Let's choose 5 to see what will happen during that 
loop. The inner loop will then iterate over the values of range(2, 5):

>>> range(2, 5)
[2, 3, 4]

So, here is what happens during the x % y:

>>> 5 % 2
1
>>> 5 % 3
2
>>> 5 % 4
1

It is never equal to 0; the print(x, "is a prime number") will execute. Perhaps 
it's the "else" clause which is confusing? From the tutorial [1], I quote:

When used with a loop, the else clause has more in common with the else clause 
of a try statement than it does that of if statements: a try statement’s else 
clause runs when no exception occurs, and **a loop’s else clause runs when no 
break occurs**. (emphasis mine)

Take care,
Don

[1] http://docs.python.org/3/tutorial/controlflow.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Two subsequent for loops in one function - I got it!

2013-11-23 Thread Don Jennings

On Nov 23, 2013, at 2:57 PM, Rafael Knuth wrote:



> 
> The output of
> 
>for y in range (2,2):
> 
> should be ... none - correct?

No, it's not none. It's an empty list; thus, python executes nothing inside the 
inner loop.

>>> range(2,2)
[]

>>> for y in range(2,2):
... print 'yes, I made it to here'
... 
>>> 

See? It has no output. By the way, the python REPL is your friend! Use it often 
when you can't figure out what is happening.

Take care,
Don

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


Re: [Tutor] Patchwork Help

2013-11-25 Thread Don Jennings

On Nov 25, 2013, at 10:54 AM, Callum Wilson wrote:

> Hi,
>  
> I am a relatively beginner to python. I am currently studying Digital 
> Forensics at University and programming using Python is currently a unit i am 
> studying.
>  
> I have to complete a worksheet for Friday 29th, but i am having trouble in 
> doing this and wanted to seek external help.
>  
> I have to create a patchwork of which begins by prompting user to enter:
> the patchwork size (common width & height in terms of patches)
> the desired 3 colours (of which my program should ensure are all different 
> from eachother).
>  
> Would you be able to help me?

Yes, we can help, but we don't do homework for you. Instead, you attempt to 
write the code, and then when you get stuck, you ask (good) questions.

>  
> if so, how do I do the things listed above?

Since you are taking a course, surely the instructor has provided you with some 
information or resources. Which ones have you tried? What doesn't make sense to 
you?

Take care,
Don

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


Re: [Tutor] strip and split?

2013-11-30 Thread Don Jennings

On Nov 30, 2013, at 1:40 PM, richard kappler wrote:

> I'm using psutil to generate some somatic data with the following script:
> 
> import psutil as ps
> 
> cpu = ps.cpu_percent()
> mem = ps.virtual_memory()
> disk = ps.disk_usage('/')
> 
> All works well, but except for cpu I am struggling to learn how to strip out 
> what I don't need.
> 
> For example, once I do the above, if I then enter "disk" I get:
> 
> disk usage(total=302264549376, used=73844322304, free=213066088448, 
> percent=24.4)
> 
> So if I want only the number following percent, I get that I need to convert 
> this to a built in type and do some split and strip

You could take that approach, but you might find that this one is easier:

>>> psutil.disk_usage('/')[-1:][0]
91.2

Take care,
Don

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


Re: [Tutor] strip and split?

2013-11-30 Thread Don Jennings

On Nov 30, 2013, at 4:32 PM, Wolfgang Maier wrote:

> richard kappler  gmail.com> writes:
> 
>> 
>> I'm using psutil to generate some somatic data with the following script:
>> 
>> import psutil as ps
>> 
>> cpu = ps.cpu_percent()
>> mem = ps.virtual_memory()
>> disk = ps.disk_usage('/')
>> 
>> All works well, but except for cpu I am struggling to learn how to strip
> out what I don't need.
>> 
>> For example, once I do the above, if I then enter "disk" I get:
>> 
>> disk usage(total=302264549376, used=73844322304, free=213066088448,
> percent=24.4)
>> 
>> So if I want only the number following percent, I get that I need to
> convert this to a built in type and do some split and strip, but that's
> where I'm floundering. Might I get a little guidance on this please?
>> 
> 
> I don't think you have to do any such thing. AFAICT, your code sets disk to
> a usage object that has all the information stored in its attributes. Try, 
> e.g.,
> 
> disk.percent

Yes! I like that much better than my suggestion.

Take care,
Don

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


Re: [Tutor] i installed the package statsmodels but i get an error when i use it

2013-12-16 Thread Don Jennings

On Dec 16, 2013, at 11:56 AM, eva maria gualandi wrote:

> Good afternoon, 
> I installed from https://pypi.python.org/pypi/statsmodels the package 
> statsmodels for python 2.7 (32bit) , i have to do some test statistics for a 
> time series analysis that i can find under statsmodels.tsa. In particular i 
> really need to do a Dickey Fuller test and in agreement with the statsmodels 
> documentation ( from 
> http://statsmodels.sourceforge.net/devel/generated/statsmodels.tsa.stattools.adfuller.html
>  ) i run this simple programm
> 
> import numpy as np
> import statsmodels
> from statsmodels.tsa import stattools
> x = np.array([1,2,3,4,3,4,2,3])
> result = statsmodels.tsa.statools.adfuller(x,1)
> print result
> 
> but unfortunately i get the following error message:
> 
> Traceback (most recent call last):
>   File "C:\Python27\esempio_adftest.py", line 3, in 
> from statsmodels.tsa import stattools
>   File "C:\Python27\lib\site-packages\statsmodels\tsa\stattools.py", line 7, 
> in 
> from statsmodels.regression.linear_model import OLS, yule_walker
>   File "C:\Python27\lib\site-packages\statsmodels\regression\__init__.py", 
> line 1, in 
> from linear_model import yule_walker
>   File 
> "C:\Python27\lib\site-packages\statsmodels\regression\linear_model.py", line 
> 37, in 
> from statsmodels.tools.tools import (add_constant, rank,
>   File "C:\Python27\lib\site-packages\statsmodels\tools\__init__.py", line 1, 
> in 
> from tools import add_constant, categorical
>   File "C:\Python27\lib\site-packages\statsmodels\tools\tools.py", line 14, 
> in 
> from pandas import DataFrame
>   File "C:\Python27\lib\site-packages\pandas\__init__.py", line 15, in 
> 
> raise ImportError('C extensions not built: if you installed already '
> ImportError: C extensions not built: if you installed already verify that you 
> are not importing from the source directory

The message is from pandas, actually. Take a look at this page [1] for 
suggestions.

Take care,
Don

[1] http://stackoverflow.com/questions/10158613/importing-confusion-pandas
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] another better way to do this ?

2014-01-11 Thread Don Jennings

On Jan 11, 2014, at 4:24 PM, Roelof Wobben wrote:

> Hello, 
>  
> I try to learn python by following the audicity page.
>  
> Now I have the following problem.
>  
> I have two strings a and b 
>  
> Now I have to check if the characters of b are all in a.
> But they do have to be in the same order. 

Perhaps they are looking for something like:

>>> 'abc' in 'someotherabcstring'
True

I suspect that you'll want to figure out how to do that same task with 
variables now :>)

Take care,
Don

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