[Tutor] Confirmation about __init__()

2010-01-16 Thread Robert
I have read quite a bit in the past 2 months, ( I have also looked at codes)
At this point, I think I understand well what __init__() is and does -
But, I have yet to see this *specifically* spelled out about the the
__init__ method for a Class;

It is OPTIONAL, correct ?

if I have NO start values/variables to set, no Base Class __init__ to
call --- the __init__ method is NOT required, correct ?

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


[Tutor] command line invocation

2010-01-17 Thread Robert
Say that I have module "spam.py"  in  "/tmp" which is in PYTHONPATH.

in shell, my current directory is "/tmp",
are line#3 and #4 --- http://paste.pocoo.org/show/166268/ -
"equivalent" --- i.e. yielding the same result ?

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


[Tutor] Confirmation about __init__()

2010-01-17 Thread Robert
I have read quite a bit in the past 2 months, ( I have also looked at codes)
At this point, I think I understand well what __init__() is and does -
But, I have yet to see this *specifically* spelled out about the the
__init__ method for a Class;

It is OPTIONAL, correct ?

if I have NO start values/variables to set, no Base Class __init__ to
call --- the __init__ method is NOT required, correct ?

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


Re: [Tutor] Subclassing object

2010-01-17 Thread Robert
On Sun, Jan 17, 2010 at 12:47 PM, Robert  wrote:
> On Sun, Jan 17, 2010 at 11:25 AM, Alan Gauld  
> wrote:
>> In older versions of Python it made a difference whether you used object
>> or not. Using object gave you a "new style" class which has several extra
>> features, without you got an "old style class" without the features.


I have been wondering about this "New-style Class" subject along this line:

so, *theoretically speaking*, in EXISTING, pre-P3K code,
if one changes everywhere where it's coded "class someClass()" to
"class someClass(object)",
it should not break the programs, right ?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] what is dynamic about "dynamic name resolution" ?

2010-01-17 Thread Robert
In the Python tutorial (highlighted here http://awurl.com/N1XvzIo2Q)

What exactly is "dynamic name resolution" ? specifically what is
"dynamic" about it ?

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


Re: [Tutor] need help in python

2010-01-21 Thread Robert
And your question is ?


On Thu, Jan 21, 2010 at 12:48 PM, invincible patriot
 wrote:
> hi
> I am a student and i need soe help regarding my assignmentif some one can
> help me il be glad.
>
> i wil be waiting for the reply
>
> thanks
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Hello

2010-01-21 Thread Robert
Check out wingware IDE and Geany.


On Thu, Jan 21, 2010 at 12:33 PM, Samuel de Champlain
 wrote:
> This is my first message to this mailing list.
> I want to create a project with glade and pygtk on fedora.
> Can you suggest a good IDE?
>
> ___
> Tutor maillist  -  tu...@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Bowing out

2010-03-03 Thread Robert
so you're "done" with Python ? :)


> On 3 March 2010 14:17, Kent Johnson  wrote:
>> After six years of tutor posts my interest and energy have waned and
>> I'm ready to move on to something new.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] a class query

2010-06-07 Thread Robert
lol,  for a second I thought this question comes from PayPal



On Mon, Jun 7, 2010 at 10:01 AM, Payal  wrote:
> Hi all,
> I know the difference  between
> class Parent :
> class Parent(object) :
>
> But in some softwares i recall seeing,
> class Parent() :
>
> Is this legal syntax?
>
> With warm regards,
> -Payal
> --
>
>
>
> ___
> Tutor maillist  -  tu...@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Book recomandation!

2010-07-15 Thread Robert
'Building Skills in Python" by Steven Lott, This free book is simply awesome
http://homepage.mac.com/s_lott/books/python.html

I went thru the "short" books first : "Dive Into Python" and "Byte of
Python" - they are good for a bit of foundation then come to this one,
and this one rreinforces concepts and explain things in a much more
organized and clear-cut way.


On Thu, Jul 15, 2010 at 5:07 PM, Daniel  wrote:
> Hello, I recently browsed the BeginnersGuide/NonProgrammers section of the
> Python website, but I have a question regarding it. With what book I should
> start learning Python? Or should I take them in the order they are presented
> there on the website?I have no previous programming experience, thanks.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how i can change two lists into one directory

2010-07-22 Thread Robert
looks like this guy figured out how to send email in a loop
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to do excel in python

2010-08-05 Thread Robert
> hi,
> can any one tell me how can I access MS excel worksheet in python and how
> can I access itz individual cells..??


let me google that for you...
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] O'Reilly is offering Learning Python (4th ed.), eBook form for USD 9.99

2010-08-11 Thread Robert
Rather depressing to see what's generally considered "Bible on Python"
among those other boring, nondescript books.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Pastebin.com fork based completely on Python (Django)

2010-09-08 Thread Robert
Does not *look* "Pythonic" - have a look at this : http://paste.pocoo.org/


On Tue, Sep 7, 2010 at 6:00 PM, Carlos Guerrero
 wrote:
> I did a "pastebin.com" fork in Django
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Change to Class-level Variable

2010-10-03 Thread Robert
Why is "f1" not affected by the Class-level variable change below ?

>>> class Foo( object ):
... myid = 'Foo'
... def __init__( self ):
...pass
...
>>> f1 = Foo()
>>> f2 = Foo()
>>> f1.myid = 'Bar'
>>> Foo.myid = 'SPAM'
>>> f1.myid <--- Why is "f1" not affected by the 
>>> Class variable change ?
'Bar'
>>> f2.myid
'SPAM'
>>> f4 = Foo()
>>> f4.myid
'SPAM'
>>>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] adding quotation marks around variables

2005-07-10 Thread Robert



Hello all, I am a college student and I am currently 
working on a two numbers program for our class, The purpose of this program is 
to take user input and do some math functions. 
 
I have figured out how to do the math but I need to 
display these two variables with quotation marks around them. 
 
Also I need to add these two variables together 
 and display the hexadecimal of these two variables???
 
Also how do you display wheather one variable is greater 
than or less than or equal to the other variable?
 
 
Below is an example of the items i need help 
with?
 


The two numbers were "X" and 
"Y." The first number was (< > =) the second number. 
The hexadecimal sum of the two numbers is XXX.
 
Any help with this would be gratly appreciated! 

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


Re: [Tutor] Ideas and good examples

2011-02-03 Thread Robert

On 2011-02-03 19:14:40 -0500, Alan Gauld said:


"Tino Dai"  wrote


Finally you should check out Alan Gauld's page:
http://www.freenetpages.co.uk/hp/alan.gauld/


That site has been locked for over 2 years. The new
site has a lot of updates and, of course, a whole new
rewrite of the tutor for v3! :-)

See the sig...


That's awesome. I think I have the original book you did in storage 
(many moons ago).  :-)


--
Robert


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


[Tutor] Python Hard_way 40

2011-05-11 Thread Robert .
Hi all,

My first post ever! :)
I'm following the guide "Learn Python the Hard Way" and have reached a point
where I am struggling to understand the code and unfortunately the authors
guide hasn't cleared it up for me. (excercise 40 for reference)

The main confusion is coming from* 'cities['_find'] = find_city'* I'm not
sure what this is really doing.

>From my learning, this should add an extra item to the dict with the index
name of "_find" and the value which is returned from "find_city" function.

run I add "print cities" after the above function to try and look at how the
dict is now populated, I am still confused.

(PasteBin version to see highlighting and indents  ->
http://pastebin.com/gmngh6sc   Not sure how it will look in email)
--
cities = {'ca': 'San Fran','MI':'detroit','FL':'Jacksonville'}

cities['NY']= 'New York'
cities['OR']= 'Portland'

def find_city(themap, state):
if state in themap:
return themap[state]
else:
return "Not found"

cities['_find'] = find_city


while True:
print "State? (Enter to quit)",
state = raw_input("> ")

if not state:
break

city_found = cities['_find'](cities,state)
print city_found

--

Grateful for any help in explaining how this program is working and each
step it is taking.

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


Re: [Tutor] Python and the web

2011-05-22 Thread Robert

On 2011-05-22 14:09:39 -0400, michael scott said:

I want to start getting into web site development. I already know basic 
html and css, which will create a basic webpage. But my question is 
what exactly does python bring to the web?


Are forums, blogs, flash sites, etc the results of web programming or 
can they all be achieved with standard html / css? What exactly can I 
do differently with python than with html and css? Or should I say, how 
can I use python WITH html and css to create something better?





You might be interested in this if you are going the Python3 route:

Python 3 Web Development Beginner's Guide [Paperback]

I am not affiliated with the book at all...just saw it today.

--
Robert


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


[Tutor] decorators

2011-06-23 Thread Robert
Is there a good tutorial out there somewhere about decorators? Google 
doesn't bring up much.


--
Robert


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


RE: [Tutor] Creating & Handling lots of objects

2004-12-03 Thread Robert, Andrew
Although I have never done so, I believe you can also store/manipulate
objects in a database.

Has anyone ever worked this option?


Thank you,
Andrew Robert
Systems Architect
Information Technology - OpenVMS
Massachusetts Financial Services
Phone:  617-954-5882
Pager:   781-764-7321
E-mail:  [EMAIL PROTECTED]
Linux User Number: #201204

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Kent Johnson
Sent: Friday, December 03, 2004 7:42 AM
To: Python Tutor
Subject: Re: [Tutor] Creating & Handling lots of objects

If you want to be able to access the objects by name, you can put them
in a dict. For example,
MyObjects={}
l=["a","b","c"]
for i in l:
MyObjects[i] = MyClass(i)

Then you can refer to MyObjects["a"]

If all the operations on the objects are done to all objects in a batch,
putting them in a list 
might work. Then you can use list iteration to access all of them:
MyObjects=[]
l=["a","b","c"]
for i in l:
MyObjects.add(MyClass(i))

then to process all the objects:
for myObj in MyObjects:
 # do something with myObj

Kent


Matt Williams wrote:
> Dear Tutor-list,
> 
> I'm sorry for this appallingly dumb question, but I'm having a little
> problem with objects.
> 
> I've written a class, with some methods. I then want to be able to
call
> the class repeatedly, to create some objects. The number of objects,
and
> some of their initialisation parameters need to be specified later
(i.e.
> at run-time).
> 
> When I generate all these objects, how do I keep track of them. For a
> finite (and small) number I can do this:
> 
> a=MyClass("a")
> b=MyClass("b")
> 
> but this is obviously not scaleable. If I use a list, I can do:
> 
> MyObjects=[]
> l=["a","b","c"]
> for i in l:
>   MyObjects.add(MyClass(i))
> 
> but then I have to search the list (MyObjects) for the object where
> Object.name="a".
> 
> The only other option seems to be finding objects via their hash
codes,
> which I'm sure isn't right
> 
> I'd like to be able to automate something closer to the a=MyClass("a")
> but don't know how to do itIt may be that I'm trying to do it very
> badly, which is Python seems to make it hard for me.
> 
> Thanks,
> 
> Matt
> 
> 
> 
> ___
> Tutor maillist  -  [EMAIL PROTECTED]
> http://mail.python.org/mailman/listinfo/tutor
> 
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


"MFS Relay Service" made the following
 annotations on 12/03/2004 08:05:23 AM
--
This email communication and any attachments may contain proprietary, 
confidential, or privileged information.  If you are not the intended 
recipient, you are hereby notified that you have received this email in error 
and that any review, disclosure, dissemination, distribution or copying of it 
or its contents is prohibited.  The sender does not waive confidentiality or 
any privilege by mistransmission.  If you have received this email in error, 
please notify the sender immediately, delete this email, and destroy all copies 
and any attachments.
==

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


RE: [Tutor] Create a binary for a python game

2004-12-03 Thread Robert, Andrew
 Sure is.

Try cx_freeze.

It can be found at
http://starship.python.net/crew/atuining/cx_Freeze/index.html .

I've used it with great success.


Thank you,
Andrew Robert
Systems Architect
Information Technology - OpenVMS
Massachusetts Financial Services
Phone:  617-954-5882
Pager:   781-764-7321
E-mail:  [EMAIL PROTECTED]
Linux User Number: #201204

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of David Holland
Sent: Friday, December 03, 2004 3:11 PM
To: [EMAIL PROTECTED]
Subject: [Tutor] Create a binary for a python game

I have created a simple python game and I would like
to convert it into a binary  executable that can be
used to play it in Linux without needing the various
libraries (pygame etc).  Is this possible ?



___ 
Win a castle for NYE with your mates and Yahoo! Messenger 
http://uk.messenger.yahoo.com
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


"MFS Relay Service" made the following
 annotations on 12/03/2004 03:23:18 PM
--
This email communication and any attachments may contain proprietary, 
confidential, or privileged information.  If you are not the intended 
recipient, you are hereby notified that you have received this email in error 
and that any review, disclosure, dissemination, distribution or copying of it 
or its contents is prohibited.  The sender does not waive confidentiality or 
any privilege by mistransmission.  If you have received this email in error, 
please notify the sender immediately, delete this email, and destroy all copies 
and any attachments.
==

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


RE: [Tutor] Connecting to interactive program

2004-12-07 Thread Robert, Andrew
 
Have you considered redirecting input from the terminal session itself?


On Linux, I think you can test against sys.stdin.isatty() and assign a
variable to /dev/tty.

The methodology is similar on Windows but you need to import msvcrt and
grab msvcrt.getche().


Thank you,
Andrew Robert
Systems Architect
Information Technology - OpenVMS
Massachusetts Financial Services
Phone:  617-954-5882
Pager:   781-764-7321
E-mail:  [EMAIL PROTECTED]
Linux User Number: #201204

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Vincent Nijs
Sent: Tuesday, December 07, 2004 2:38 PM
To: [EMAIL PROTECTED]
Subject: Re: [Tutor] Connecting to interactive program

Has anyone ever tried to send commands to a running interactive python
session from, say, the command line or another app?

If so, please let me know how you achieved this.

Vincent


On 12/1/04 4:10 PM, "Vincent Nijs" <[EMAIL PROTECTED]>
wrote:

> Hi,
> 
> I am trying to send information from an editor (vim) to an interative
> program (say the Python commandline, R, Matlab, etc.).
> 
> I have tried to connect a named pipe to the interactive program using
> mkfifo. For some reason this doesn't work properly however (
seems to
> be the first thing sent).
> 
> Could anyone provide a very very simple example where from a terminal
> command line I could send, say, 'x=3' to an open interactive python
session?
> I'd like to have something that works on WinXP and Mac (or Linux).
> 
> Thanks!
> 
> Vincent

-- 



___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


"MFS Relay Service" made the following
 annotations on 12/07/2004 03:00:42 PM
--
This email communication and any attachments may contain proprietary, 
confidential, or privileged information.  If you are not the intended 
recipient, you are hereby notified that you have received this email in error 
and that any review, disclosure, dissemination, distribution or copying of it 
or its contents is prohibited.  The sender does not waive confidentiality or 
any privilege by mistransmission.  If you have received this email in error, 
please notify the sender immediately, delete this email, and destroy all copies 
and any attachments.
==

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


RE: [Tutor] Difference between for i in range(len(object)) and for i in object

2004-12-09 Thread Robert, Andrew
 Good morning Kumar,

I believe you need to do something like:

   #
   # Read from command line supplied input file
   #
   for line in open(sys.argv[1]).xreadlines():

#
# Remove \n from end of line
#
line=line[:-1]

#
# Break line by tab delimiter and feed to list
#
split_line_by_tab=line.split('\t')
  

You should then be able to print out list items relatively easily.


Thank you,
Andrew Robert
Systems Architect
Information Technology - OpenVMS
Massachusetts Financial Services
Phone:  617-954-5882
Pager:   781-764-7321
E-mail:  [EMAIL PROTECTED]
Linux User Number: #201204

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of kumar s
Sent: Thursday, December 09, 2004 11:51 AM
To: [EMAIL PROTECTED]
Subject: [Tutor] Difference between for i in range(len(object)) and for
i in object

Dear group, 
  

My Tab delimited text looks like this:

HG-U95Av2   32972_at432 117
HG-U95Av2   32972_at499 631
HG-U95Av2   32972_at12  185
HG-U95Av2   32972_at326 83
HG-U95Av2   32972_at62  197


I want to capture: columns 2 and 3 as tab delim. text:


Here is my code:
>>> spot_cor=[]
>>> for m in cor:
... cols = split(cor,'\t')
... spot_cor.append(cols[2]+'\t'+cols[3])
...
...
Traceback (most recent call last):
  File "", line 2, in ?
  File "/usr/local/lib/python2.3/string.py", line 121,
in split
return s.split(sep, maxsplit)
AttributeError: 'list' object has no attribute 'split'

Here is 2nd way:


>>> test_cor=[]
>>> for m in cor:
... cols = split(cor,'\t')
... x = (cols[2]+'\t'+cols[3])
... test_cor.append(x)
...
Traceback (most recent call last):
  File "", line 2, in ?
  File "/usr/local/lib/python2.3/string.py", line 121,
in split
return s.split(sep, maxsplit)
AttributeError: 'list' object has no attribute 'split'



Here is my 3rd way of doing this thing:
>>> for m in range(len(cor)):
... cols = split(cor[m],'\t')
... spot_cor.append(cols[2]+'\t'+cols[3])
...
>>>
>>> len(spot_cor)
2252
>>>



My question:
 Many people suggested me to avoid  iteration over  a
object using (range(len)) its index and use instead
'Python's power' by using for i in object, instead. 

However, when I tried that using some data, as
demonstrated above, I get error because append method
does not work on list.  In method 2, i tried to append
an object instead of string elements. In both ways the
execution failed because  'List object has no
attribute split'.


Can you help me making me clear about his dogma. 


Thank you. 

Kumar.



--- Guillermo Fernandez Castellanos
<[EMAIL PROTECTED]> wrote:

> Cheers,
> 
> I think your mistake is here:
> if x == y:
>for ele3 in spot_int:
>if y in ele3:
>   
> out.write(ele3)
>   
> out.write('\n')
> Each time you find an element that is the same
> (x==y) you don't write
> only y, you write *all* the elements that are in
> spot_init instead
> only the matching one! And it's not what you are
> looking for! :-)
> 
> I'll also change a bit your code to make it look
> more "pythonic" :-)
> 
> > for ele1 in spot_cor:
> > for ele2 in spot_int:
> > cols = split(ele2,'\t')
> > y = (cols[0]+'\t'+cols[1])
> > if ele1 == y:
> > for ele3 in spot_int:
> > if y in ele3:
> >
> out.write(ele3)
> >
> out.write('\n')
> 
> What changes I did:
> 
> for ele1 in range(len(spot_cor)):
>x = spot_cor[ele1]
> 
> can be writen like:
> for ele1 in spot_cor:
> x = ele1
> 
> Furthermore, as you only use x once, I changed:
>  if x == y:
> 
> with
> if ele1 == y:
> 
> and deleted the line:
> x = ele1
> 
> I also don't understand why you do this:
> cols = split(ele2,'\t')
> y = (cols[0]+'\t'+cols[1])
> 
> It seems to me that you are separating something to
> put it again
> together. I don't really see why...
> 
> Enjoy,
> 
> Guille
> 




__ 
Do you Yahoo!? 
Yahoo! Mail - now with 250MB free storage. Learn more.
http://info.mail.yahoo.com/mail_250
___

RE: [Tutor] hello i need help

2004-12-16 Thread Robert, Andrew
I recommend you use vim.

You can get it at http://www.vim.org/download.php


Thank you,
Andrew Robert
Systems Architect
Information Technology - OpenVMS
Massachusetts Financial Services
Phone:  617-954-5882
Pager:   781-764-7321
E-mail:  [EMAIL PROTECTED]
Linux User Number: #201204

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jason Child
Sent: Thursday, December 16, 2004 2:43 PM
To: [EMAIL PROTECTED]
Subject: Re: [Tutor] hello i need help

alex biggerstaff wrote:

> is it possible 2 write a script for wordpad or something, i only 
> started so i dont know much
> i do know a little about if ($1 == hi)  && (£2 == m8)
> but im not sure how 2 make this apply to other programs. i can only 
> write scripts on a thing called mIRC.
> ne help would b great
> thnxs
>
> * ALL-NEW Yahoo! Messenger * 
> <http://uk.rd.yahoo.com/evt=21626/*http://uk.messenger.yahoo.com> * - 
> all new features - even more fun!* * *
>
>
>
>___
>Tutor maillist  -  [EMAIL PROTECTED]
>http://mail.python.org/mailman/listinfo/tutor
>  
>

I do not belive that Notepad supports scripting. Take a look at: 
http://www.python.org/moin/PythonEditors

in particular you may want to look at JeXt, Syn or Zues.


___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


"MFS Relay Service" made the following
 annotations on 12/16/2004 03:01:08 PM
--
This email communication and any attachments may contain proprietary, 
confidential, or privileged information.  If you are not the intended 
recipient, you are hereby notified that you have received this email in error 
and that any review, disclosure, dissemination, distribution or copying of it 
or its contents is prohibited.  The sender does not waive confidentiality or 
any privilege by mistransmission.  If you have received this email in error, 
please notify the sender immediately, delete this email, and destroy all copies 
and any attachments.
==

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Is it pythonesque

2010-01-24 Thread Robert Berman
Good morning,

 

Given the following code snippets:

 

def getuserinput():

while True:

s1 = raw_input('Enter fraction as N,D or 0,0 to exit>>')

delim = s1.find(',')

if delim < 0:

print 'invalid user input'

else:

n = int(s1[0:delim])

d = int(s1[delim+1::])

return n,d

 

def main():

while True:

n,d = getuserinput()

if n == 0 or d == 0: return 0

 

n and d are always returned provided the input is given as n,d. n/d will
print an error message and the loop will reiterate until the user format is
correct. Please note there is no true ending return for getuserinput() as it
is hung off an if statement and if by some  chance it breaks, it should
return None which will abort the program. While I suspect this style is
devious, is it dangerous or 'wrong' to use. Comments and other renditions
are most welcome.

 

Thank you,

 

Robert Berman

 

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


Re: [Tutor] Is it pythonesque

2010-01-24 Thread Robert Berman
Thank you for the snippet and the insight.


Robert

-Original Message-
From: tutor-bounces+bermanrl=cfl.rr@python.org
[mailto:tutor-bounces+bermanrl=cfl.rr@python.org] On Behalf Of Alan
Gauld
Sent: Sunday, January 24, 2010 12:17 PM
To: tutor@python.org
Subject: Re: [Tutor] Is it pythonesque


"Robert Berman"  wrote

> def getuserinput():
>while True:
>s1 = raw_input('Enter fraction as N,D or 0,0 to exit>>')
>delim = s1.find(',')
>if delim < 0:
>print 'invalid user input'
>else:
>n = int(s1[0:delim])
>d = int(s1[delim+1::])
>return n,d

Personally I'd do this with

try:
 n,d = s1.split(',')
 return int(n),int(d)
except ValueError:
 print 'invalid user input'
 continue


Note ValueError works for both the int conversion and the split() 
assignment

> def main():
>while True:
>n,d = getuserinput()
>if n == 0 or d == 0: return 0

> correct. Please note there is no true ending return for getuserinput() as 
> it
> is hung off an if statement and if by some  chance it breaks, it should
> return None which will abort the program.

Since you are inside an infinite loop you should only break if you get an
uncaught exception which will generate a stack trace anyhow

That seems fair enough to me...

HTH,


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/ 


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

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


Re: [Tutor] can any one help

2010-01-31 Thread Robert Berman
Grigor Kolev 

From: tutor-bounces+bermanrl=cfl.rr@python.org
[mailto:tutor-bounces+bermanrl=cfl.rr@python.org] On Behalf Of
invincible patriot
Sent: Sunday, January 31, 2010 5:03 AM
To: rabidpoob...@gmail.com; grigor.ko...@gmail.com
Cc: tutor@python.org
Subject: Re: [Tutor] can any one help

please check the questions below.

1
 1.1 Write a Python program with a loop that prints out a sequence of
numbers as follows:
15
13
11
...
3
1
-1


1.2 Write a small Python program that generates the list of all pairs of
characters c and
its doubling 2  c, where c moves through all the letters of the string
"foobar" and prints it out.
The result will look like:
[(’f’, ’ff’), (’o’, ’oo’), (’o’, ’oo’), (’b’, ’bb’), (’a’, ’aa’), (’r’,
’rr’)]
Hint: use list comprehensions.
.


What possible reason would you have for expecting anyone n this group to do
your school work for you?

If you really want help, show us the status of your current scripts and
quote us the errors you are receiving.

Good luck,

Robert

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


Re: [Tutor] Future Appointments...

2010-01-31 Thread Robert Berman


-Original Message-
From: tutor-bounces+bermanrl=cfl.rr@python.org
[mailto:tutor-bounces+bermanrl=cfl.rr@python.org] On Behalf Of Ken G.
Sent: Sunday, January 31, 2010 10:41 AM
To: tutor@python.org
Subject: [Tutor] Future Appointments...

Below is a program to determine when my next appointment is.  Line 
numbers are provided for reference only.

01  import time, datetime, sys
02  from datetime import date
03  today = date.today()
04  print
05  print "Today date is:", today
06  todaystr = str(today)
07  print
08  print "Corrected date format is:",
09  print todaystr[ 5: 7], todaystr[ 8:10], todaystr[ 0: 4]
10  print
11  future = raw_input("Next appointment is in how many days?  "),
12  print
13  difference1 = datetime.timedelta(days=1)
14  datestring = str(today + difference1)
15  print "Next appointment after that is:",datestring
16  print
17  print "Corrected date format for next appointment is:",
18  print datestring[ 5: 7], datestring[ 8:10], datestring[ 0: 4]
19  sys.exit()

In answering the question in line 11 as to when is my next appointment, 
I would answer "3" (for 2/3/2010) but how do I change "days=1" at end of 
line 13 to "days=3" so that datestring would read "2010-02-03" instead 
of "2010-02-01" as presented above?

TIA,

Ken
*

Hi Ken,

I slightly altered your program. I think this is what you asked for. It will
work for n number of days; for example, 1, 10, 45, 118, 412 work nicely.

See code here: http://pastebin.com/m6e78d3ce

Robert

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


Re: [Tutor] rstrip in list?

2010-02-09 Thread Robert Berman


-Original Message-
From: tutor-bounces+bermanrl=cfl.rr@python.org
[mailto:tutor-bounces+bermanrl=cfl.rr@python.org] On Behalf Of Ken G.
Sent: Tuesday, February 09, 2010 10:29 AM
To: tutor@python.org
Subject: [Tutor] rstrip in list?

I printed out some random numbers to a list and use 'print mylist' and
they came out like this:

['102\n', '231\n', '463\n', '487\n', '555\n', '961\n']

I was using 'print mylist.rstrip()' to strip off the '\n'

but kept getting an error of :

AttributeError: 'list' object has no attribute 'rstrip'

My memory must be hazy but I thought I had it working several months ago.

Any idea or suggestion?

TIA, Ken

In [14]: mylist
Out[14]: ['102\n', '231\n', '463\n', '487\n', '555\n', '961\n']

In [15]: for item in mylist:
   : print item.strip('\n')
   :
   ....:
102
231
463
487
555
961


I get the impression you can strip something from the elements in the list,
but that it balks at a change to the  entire list in a single statement?


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

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


Re: [Tutor] Wrestling with the Py2exe Install, Win7[XP!], Py2.5

2010-02-17 Thread Robert Berman
> -Original Message-
> From: tutor-bounces+bermanrl=cfl.rr@python.org [mailto:tutor-
> bounces+bermanrl=cfl.rr@python.org] On Behalf Of Wayne Watson
> Sent: Wednesday, February 17, 2010 10:48 AM
> To: *tutor python
> Subject: [Tutor] Wrestling with the Py2exe Install, Win7[XP!], Py2.5
> 
> (This is the same msg as above, but I meant XP. I'm transitioning
> from
> XP to Win7, and am operating with two monitors and keyboards side by
> side. I thought I had used W7, but nope. Corrected wrestling it
> Subject.)
> 
> I've finally decided to see if I could make an executable out of a
> py
> file. XP. Py2.5. I brought down the install file and proceeded with
> the
> install. I got two warning messages. Forgot the first. The second
> said,"Could not set the key value." I again used OK. I think that
> was
> the only choice. It then issued a message in a larger dialog. I've
> attached it here, but have had zero luck recently and in the past.
> It
> was about setting a key, and pointed me to a log. It mentions a
> Removepy2exe -u
> 
> Although it finished, I have no idea where the program is. It does
> not
> show up on the Start menu All Programs List nor my desktop. What's
> up.
> 
> I've had these messages (key) occur on other Python installs as I
> transition to Win7. So far no problem.
> 
> 

Hi Wayne,

A few observations as I do this on Win 7 and it does work. The first thing you
need to do is follow the tutorial that you should get at the web page found in
the README file. If not, here it is: http://www.py2exe.org/index.cgi/Tutorial

That will get you started. Now, if everything went reasonably well, you will
find two folders in the folder where you ran py2exe called build and dist.
Ignore build. In dist you will find the exe file and all the files necessary
to run your program.gasp.sort of. There is a caveat. Sometimes you
don't get all the necessary DLL's. If you are in that situation py2exe should
have printed the files you still need to track down and include with your
install.

Now, I gave you all this information as background because we  all know that
really good programmers like mental and emotional pain. Well, perhaps some do.
I like the easy but good way when available.  Let me tell you what I use
because it takes a lot of the drudgery out of the process. Go to
http://code.google.com/p/gui2exe/ and download gui2exe. It will automate much
of the process and it seems to do a great job of finding all the necessary
files including the DLL's hidden from py2exe.

I hope this helps. It is a good concept and good software.

Robert Berman

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


Re: [Tutor] Wrestling with the Py2exe Install, Win7[XP!], Py2.5

2010-02-18 Thread Robert Berman
> -Original Message-
> From: tutor-bounces+bermanrl=cfl.rr@python.org [mailto:tutor-
> bounces+bermanrl=cfl.rr@python.org] On Behalf Of Wayne Watson
> Sent: Wednesday, February 17, 2010 10:07 PM
> To: tutor@python.org
> Subject: Re: [Tutor] Wrestling with the Py2exe Install, Win7[XP!],
> Py2.5
> 
> I'm following the tutorial and ran into a snag. Here  is the console
> output.( Can I do  this  from IDLE?)
> 
> C:\Sandia_Meteors\Sentinel_Development\Learn_Python>c:\python25\pyth
> on
> setup.py
> Traceback (most recent call last):
>File "setup.py", line 2, in 
>  import py2exe
> ImportError: No module named py2exe
> 
> Note the need to back pedal to c:\python25\
> Perhaps I need some path variable set?
> 
> --
Wayne,

When you install py2exe it should insure all the required modules are
available to your standard python path. For example, I am running python 2.64
and the py2exe module is in the python path.

I don't use IDLE. I use Ipython however I cannot see why IDLE would not work.
To tell if you are OK do import py2exe. You should have no problem loading it.
If you do, reinstall it.

Robert


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


Re: [Tutor] Wrestling with the Py2exe Install, Win7[XP!], Py2.5

2010-02-19 Thread Robert Berman
Wayne,

Somewhere in the tutorial should be a comment about py2exe creating two
additional directories: build and dist. Forget about the build directory. If
you look in the dist directory you will find the exe file and all supporting
files. If you look back to an earlier email you will see a more detailed
explanation I sent you.

Robert Berman



> -Original Message-
> From: Wayne Watson [mailto:sierra_mtnv...@sbcglobal.net]
> Sent: Thursday, February 18, 2010 11:10 PM
> To: Robert Berman
> Cc: tutor@python.org
> Subject: Re: [Tutor] Wrestling with the Py2exe Install, Win7[XP!],
> Py2.5
> 
> There's a bit of an anomaly. I've compiled 3 small programs now, and
> in
> cmd prompt a Dir does not find the file. It finds the py file, but
> not
> the completed file. Nevertheless, if I type in the prefix, the
> desired
> program executes.
> 
> On 2/18/2010 4:48 PM, Wayne Watson wrote:
> > Got it. Fooled myself. I'm converting to  Win7 and have my XP
> keyboard
> > and monitor side by side with the same for XP. I did the world
> program
> > in XP and py2exe module in W7!!
> >
> > world compiled and ran successfully. Now for a bigger program with
> > matplotlib and tkinter. Maybe I'll just settle for a small
> matplotlib
> > program for the moment. VBG
> >
> > Thanks very much.
> >
> 
> --
>  "There is nothing so annoying as to have two people
>   talking when you're busy interrupting." -- Mark Twain

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


Re: [Tutor] The Disappearing Program (py2exe)

2010-02-19 Thread Robert Berman
Wayne,

I am assuming you are using Win 7 and I'll answer with that unless you tell me
you are using XP in which case I will walk over to my wife's desk and test
what I am telling you on her XP driven machine.

Assuming Windows 7.

Looking at your directory you should be using Windows Explorer. Click on
Organize then click on folder and search options. Then click on view. Make
sure the check box that says 'hide extensions for known file types' is not
clicked. Once that is done, all your file extensions (all of them) will be
seen and shown.


Robert

> -Original Message-
> From: Wayne Watson [mailto:sierra_mtnv...@sbcglobal.net]
> Sent: Friday, February 19, 2010 12:11 PM
> To: Robert Berman
> Subject: Re: [Tutor] The Disappearing Program (py2exe)
> 
> I'm sure you are right. I'm not sure what you mean about view
> params.
> Properties?
> 
> On 2/19/2010 7:08 AM, Robert Berman wrote:
> > I think you will find that snowball is actually snowball.exe. You
> might check
> > the view parameters on how your extensions are being displayed.
> >
> >
> >> -Original Message-
> >> From: tutor-bounces+bermanrl=cfl.rr@python.org [mailto:tutor-
> >> bounces+bermanrl=cfl.rr@python.org] On Behalf Of Wayne Watson
> >> Sent: Friday, February 19, 2010 10:00 AM
> >> To: tutor@python.org
> >> Subject: [Tutor] The Disappearing Program (py2exe)
> >>
> >> I've successfully compiled several small python programs on Win
> XP
> >> into
> >> executables using py2exe. A program goes from a name like
> >> snowball.py to
> >> snowball. A dir in the command prompt window finds snowball.py
> but
> >> not
> >> snowball. If I type in snowball, it executes. What's up with
> that?
> >>
> >> --
> >>   "There is nothing so annoying as to have two people
> >>talking when you're busy interrupting." -- Mark
> Twain
> >>
> >> ___
> >> Tutor maillist  -  Tutor@python.org
> >> To unsubscribe or change subscription options:
> >> http://mail.python.org/mailman/listinfo/tutor
> >>
> >
> >
> 
> --
>  "There is nothing so annoying as to have two people
>   talking when you're busy interrupting." -- Mark Twain

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


[Tutor] Help me understand this tkinter related code

2010-02-26 Thread Robert DeLaurentis
I've just begun learning Python and programming using the Head First 
Programming from O'Reilly. The following code works on my Mac just fine, but 
there is a mystery as to how its working that escapes me so far.

The local function change_volume(v) requires the argument v to operate 
properly, but I'm unclear where the value of that argument is being set or why 
the code fails without it. It appears to be a detail that isn't explained in 
the text. When I compare the two widgets and their associated functions, both 
seem to use the .get method to access the value set by the widget, so in that 
case the v seems superfluous.

I thought that perhaps the answer might be found in the tkinter code that 
defines Scale, but I'm not even sure where on the computer that code is located.

Thank you!
Bob


Here is the code (the comments are mine, otherwise the code matches the book 
except that I grouped some items differently -- I like to keep variables all in 
one place as much as possible):


#!/usr/local/bin/python3

# load external libraries
from tkinter import *
import pygame.mixer

# initialize the visual interface
app = Tk()
app.title("Head First Mix")
app.geometry('250x100+200+100')

# initialize the sound player
mixer = pygame.mixer
mixer.init()

# initialize the variables
sound_file = "50459_M_RED_Nephlimizer.wav"
track = mixer.Sound(sound_file)
track_playing = IntVar()

# local functions
def shutdown():
track.stop()
app.destroy()

def track_toggle():
if track_playing.get() == 1:
track.play(loops = -1)
else:
track.stop()

def change_volume(v):
track.set_volume(volume.get())



# define interface widgets
track_button = Checkbutton(app, variable = track_playing, 
command = track_toggle, 
text = sound_file)

track_button.pack()

volume = DoubleVar()
volume.set(track.get_volume())
volume_scale = Scale(app,
variable = volume,
from_= 0.0,
to   = 1.0,
resolution   = 0.1,
command  = change_volume,
label= "Volume",
orient   = HORIZONTAL)

volume_scale.pack()

# main entry point
app.protocol("WM_DELETE_WINDOW", shutdown)
app.mainloop()




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


Re: [Tutor] Why is the max size so low in this mail list?

2010-03-01 Thread Robert Berman

> -Original Message-
> From: tutor-bounces+bermanrl=cfl.rr@python.org [mailto:tutor-
> bounces+bermanrl=cfl.rr@python.org] On Behalf Of Alan Gauld
> Sent: Monday, March 01, 2010 12:30 PM
> To: tutor@python.org
> Subject: Re: [Tutor] Why is the max size so low in this mail list?
> 
> 
> "Wayne Watson"  wrote
> 
> > See Subject. 40K here, but other Python lists allow for larger
> (total)
> > sizes.
> 
> Presumably to discourage long posts or posts with large attachments?
> But I'm only guessing...
> 
> Alan G
> 
> 
It encouraged me to use pastebin when it was necessary to post code a tad
longer than the casual fifteen line snippet.
 
Robert Berman
The opposite of love is not hate, it's indifference.
The opposite of art is not ugliness, it's indifference.
The opposite of faith is not heresy, it's indifference.
And the opposite of life is not death, it's indifference.
 




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


[Tutor] Binary search question

2010-04-23 Thread Robert Berman
Hi,

Given a list, list1 having 100,000 non repeating, sorted integers ,  which of
the following methods is fastest to find an item fully understanding the item
may or may not be in the list: The binary search method which is the standard
search for such a small sample size, or the more python type statement is
 in list1?

What I am really trying to ascertain is how expensive or how efficient is  'is
 in list1'.

Thanks for your input

Robert Berman

What you don't see with your eyes, don't invent with your mouth.


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


Re: [Tutor] Binary search question

2010-04-23 Thread Robert Berman
Thank you all for your ideas and suggestions. The detailed explanations were
most useful.

 

Robert Berman

 

What you don't see with your eyes, don't invent with your mouth.

 

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


Re: [Tutor] Binary search question

2010-04-23 Thread Robert Berman

> -Original Message-
> From: tutor-bounces+bermanrl=cfl.rr@python.org [mailto:tutor-
> bounces+bermanrl=cfl.rr@python.org] On Behalf Of Hugo Arts
> Sent: Friday, April 23, 2010 5:55 PM
> To: Emile van Sebille
> Cc: tutor@python.org
> Subject: Re: [Tutor] Binary search question
> 
>
>>>>>>>>>>>>>>>>>BIG SNIP   

> Of course, profiling will immediately catch that kind of performance
> bottleneck. So even if you care about performance, you can start off
> using 'in' and easily optimize later with bisect or a set, the whole
> "don't do it yet" thing and all.
> 
> Hugo

This sounds very much like the school of thought that equates optimal
efficiency with the developers level of comfort < not confidence>. So that I
might be willing to live with an occasional 7 second search time for the
general ease of using  in list. Knowing of course that eventually a
programmer who is concerned with that potential 7 second lag time will opt for
either a dictionary lookup or a bisected search.


Robert Berman

What you don't see with your eyes, don't invent with your mouth.

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

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


Re: [Tutor] Binary search question

2010-04-23 Thread Robert Berman
From: tutor-bounces+bermanrl=cfl.rr@python.org
[mailto:tutor-bounces+bermanrl=cfl.rr@python.org] On Behalf Of Ricardo
Aráoz
Sent: Friday, April 23, 2010 6:33 PM
To: Hugo Arts
Cc: tutor@python.org; Emile van Sebille
Subject: Re: [Tutor] Binary search question

Hugo Arts wrote: 
On Fri, Apr 23, 2010 at 11:33 PM, Emile van Sebille  wrote:
  
On 4/23/2010 2:21 PM Alan Gauld said...

"Emile van Sebille"  wrote
  
It's expensive enough that for a list this size I'd convert it to a
dict and use in on that. eg,

a = range(10)
d = dict(zip(a,a))


Surely that would depend on how often you do the search? If it's a one
off occurrence I'd expect the overhead of zipping and converting to a
dict would outweigh the savings?
  
Oh sure, but in practical terms, if it's a one-off situation who cares which
you us?  For a one-off I'd just use in and not be concerned.



I guess Alan missed my second e-mail with the micro benchmarks, but
that nuances my first answer quite a bit, and makes all the points he
is making. That does not make him less correct, of course. set (I used
frozenset, but either way) is faster than dict, and in a one-off
you're best off using bisect.

For completeness sake, on a 1 item list, using the in operator
takes *in the worst case* around 7 seconds. bisect, again in the worst
case, takes only around 0.01 seconds (that's on a Core 2 Duo T5300 @
1.7 GHZ, 2 GB RAM). That's quite a savings. those 7 seconds can easily
be 99% of the execution time of a typical script. So for sufficiently
large data set it can definitely pay off to be concerned, even with a
one-off

Of course, profiling will immediately catch that kind of performance
bottleneck. So even if you care about performance, you can start off
using 'in' and easily optimize later with bisect or a set, the whole
"don't do it yet" thing and all.

Hugo
___
  

In the same vein of completeness sake, and since this is the *tutor* list, we
should stress that the 'right' approach is to use 'in' whatever the case. And
only if the system is too slow and profiling shows that 'in' is the culprit
should we seek for alternatives.

Wow. I feel I have just been b…h slapped across the face. I think Hugo’s test
results pretty much confirmed ‘in’ is not the way to go although it is one of
the methods I am trying even though my tendency, since the number of elements
is always less than 1,000,000, is to use the dictionary approach. 
But, even though my years of experience using Python is less than 4 I would be
reluctant to use ‘in’ just based on what I have been reading from those who
took the time to answer my post. Just my $0.02 worth.

Robert Berman

What you don't see with your eyes, don't invent with your mouth.



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


Re: [Tutor] Binary search question

2010-04-24 Thread Robert Berman
> -Original Message-
> From: tutor-bounces+bermanrl=cfl.rr@python.org [mailto:tutor-
> bounces+bermanrl=cfl.rr@python.org] On Behalf Of Alan Gauld
> Sent: Friday, April 23, 2010 7:41 PM
> To: tutor@python.org
> Subject: Re: [Tutor] Binary search question
> 
> "Emile van Sebille"  wrote
> 
> >BIG SNIP
> 
> And even at 1000 entries, the list creation slowed right
> down - about 10 seconds, but the searches even for "-5" were
> still around a second.
> 
> So 'in' looks pretty effective to me!
> 
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/


Now that is most impressive.


Robert Berman

What you don't see with your eyes, don't invent with your mouth.



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


[Tutor] namespaces

2010-05-30 Thread Robert Johansson
Hi,

 

This code generates the message "UnboundLocalError: local variable 'doubles'
referenced before assignment" (line: if d[0] == d[1] and doubles == 2:)

 

http://pastebin.com/mYBaCfj1  

 

I think I have a fair picture of what it means but I would be very happy if
someone could explain the difference between the two variables h and doubles
in the code. Why is one accessible from the function but not the other? I
looked into rules for namespaces but I'm still confused. Below is another
sample of the code

 

Cheers, Robert

 

from random import *

 

h = 6

doubles = 0 # current number of consecutive doubles

 

def roll():

d = [randint(1, h), randint(1, h)]

if d[0] == d[1] and doubles == 2:

doubles = 0

return 0

elif d[0] == d[1] and doubles < 2:

doubles += 1

return sum(d)

else:

return sum(d)

 

for n in range(10):

d = roll()

print d

 

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


Re: [Tutor] namespaces

2010-05-30 Thread Robert Johansson
Thanks Evert for pointing out the difference and the discussion on global 
variables, it helped. 

/Robert

-Ursprungligt meddelande-
Från: Evert Rol [mailto:evert@gmail.com] 
Skickat: den 30 maj 2010 18:34
Till: Robert Johansson
Kopia: tutor@python.org
Ämne: Re: [Tutor] namespaces

  Hi Robert

> This code generates the message "UnboundLocalError: local variable 'doubles' 
> referenced before assignment" (line: if d[0] == d[1] and doubles == 2:)
>  
> http://pastebin.com/mYBaCfj1  
>  
> I think I have a fair picture of what it means but I would be very happy if 
> someone could explain the difference between the two variables h and doubles 
> in the code. Why is one accessible from the function but not the other? I 
> looked into rules for namespaces but I'm still confused. Below is another 
> sample of the code

You assign a value to doubles in the roll() function, making Python think 
doubles is a local variable (which hasn't been assigned anything when you first 
use it, throwing the exception).
If you assign some value to h after the first line in roll() (eg, h = 6), you'd 
get the same exception, but then for h.
So, if you assign a value to a variable inside a function() and you want that 
variable to be the global one (instead of the implicitly assumed local one), 
you'll have to explicitly tell Python that: "global doubles" (probably on the 
first line in the function).
Since you hadn't assigned any value to h inside roll(), only used it, Python 
assumes it's the global one.

See also the second answer to this question: 
http://stackoverflow.com/questions/423379/global-variables-in-python

Hope that helps,

  Evert


>  
> Cheers, Robert
>  
> from random import *
>  
> h = 6
> doubles = 0 # current number of consecutive doubles
>  
> def roll():
> d = [randint(1, h), randint(1, h)]
> if d[0] == d[1] and doubles == 2:
> doubles = 0
> return 0
> elif d[0] == d[1] and doubles < 2:
> doubles += 1
> return sum(d)
> else:
> return sum(d)
>  
> for n in range(10):
> d = roll()
> print d   
>  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] random graph

2010-07-13 Thread Robert Johansson
Dear all,

 

I'm trying to check the size of a component in a random graph with this code
(by a component I mean a maximal connected sub graph):

 

http://pastebin.com/SzC77HdU

 

I'm not 100 % sure that the code is working as it should but my question is
if there is a better way to design the whole thing. 

 

Basically I start with a empty graph (just a set of nodes represented as the
numbers between 0 and 10 ** 6) and generate random edges as pairs of
integers between 0 and 10 ** 6. Also I keep a dictionary (comps) matching
nodes to component numbers. If one of the nodes of the new edge doesn't
touch an existing component, I just add that node to the dictionary and give
it the same component number as the other node. If no node touches a
component the a new component number is generated and the new nodes are
added to the dict with that number. The problem is when an edge going
between two distinct components are encountered, say that edge (n, m) is
generated going between component i and j. Now I need to change all values
for keys in one of the components to the values of the other component so
that  they merge into a single component. The way I tried to do this is to
have lists of length one as values in the dict and by that (hopefully)
manage to update all values for a whole component just by changing a single
list item (I think of them as pointers to the same list).  

 

Will this work? Is there a better way to update the values of a component
(fast)?

 

/Robert

 

 

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


Re: [Tutor] has it gone quiet or is it just me?

2010-07-21 Thread Robert Berman
Same.

Robert

> -Original Message-
> From: tutor-bounces+bermanrl=cfl.rr@python.org [mailto:tutor-
> bounces+bermanrl=cfl.rr@python.org] On Behalf Of Luke
> Paireepinart
> Sent: Wednesday, July 21, 2010 2:05 PM
> To: Alan Gauld
> Cc: tutor@python.org
> Subject: Re: [Tutor] has it gone quiet or is it just me?
> 
> Not sure Alan.
> I haven't gotten any messages either, but this one came through just
> fine.
> -Luke
> 
> On Wed, Jul 21, 2010 at 12:55 PM, Alan Gauld
>  wrote:
> > I haven't had any tutor messages in 2 days.
> > Do I have a problem or are things just very quiet suddenly?
> > The archive isn't showing anything either which makes me
> suspicious.
> >
> > ___
> > Tutor maillist  -  tu...@python.org
> > To unsubscribe or change subscription options:
> > http://mail.python.org/mailman/listinfo/tutor
> >
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

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


Re: [Tutor] prime test problem

2010-08-21 Thread Robert Berman
Googling 'computing prime numbers' produced about 64,100,000 results . That
should certainly get you started.

 

Robert

 

From: tutor-bounces+bermanrl=cfl.rr@python.org
[mailto:tutor-bounces+bermanrl=cfl.rr@python.org] On Behalf Of Roelof
Wobben
Sent: Saturday, August 21, 2010 9:36 AM
To: tutor@python.org
Subject: [Tutor] prime test problem

 

Hello, 
 
I have to make a programm which can test if a number is a prime.
I know a prime is a number which can only be diveded by 1 and itself.
 
One way is was thinking about is to make a loop which try if % has output 0.
But that don't work.
 
Can someone give me a hint what's the best approach is.
 
Roelof
 

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


Re: [Tutor] data question

2010-10-02 Thread Robert Berman


> -Original Message-
> From: tutor-bounces+bermanrl=cfl.rr@python.org [mailto:tutor-
> bounces+bermanrl=cfl.rr@python.org] On Behalf Of Roelof Wobben
> Sent: Saturday, October 02, 2010 4:35 AM
> To: tutor@python.org
> Subject: [Tutor] data question
> 
> 
> 
> Hello,
 
> Now my question is :
> 
> In which datatype can I put this data in.
> 
Perhaps a simple SQLlite database? 
http://zetcode.com/databases/sqlitetutorial/

Hope this helps,

Robert


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

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


Re: [Tutor] Merging Text Files

2010-10-13 Thread Robert Jackiewicz
On Wed, 13 Oct 2010 14:16:21 -0600, Ara Kooser wrote:

> Hello all,
> 
>   I am working on merging two text files with fields separated by
>   commas.
> The files are in this format:
> 
> File ONE:
> *Species, Protein ID, E value, Length* Streptomyces sp. AA4,
> ZP_05482482, 2.82936001e-140, 5256, Streptomyces sp. AA4,
> ZP_05482482, 8.03332997e-138, 5256, Streptomyces sp. AA4,
> ZP_05482482, 1.08889e-124, 5256, Streptomyces sp. AA4, ZP_07281899,
> 2.92539001e-140, 5260,
> 
> File TWO:
> *Protein ID, Locus Tag, Start/Stop*
> ZP_05482482, StAA4_010100030484,
> complement(NZ_ACEV0178.1:25146..40916) ZP_07281899, SSMG_05939,
> complement(NZ_GG657746.1:6565974..6581756)
> 
> I looked around for other posts about merging text files and I have this
> program:
> one = open("final.txt",'r')
> two = open("final_gen.txt",'r')
> 
> merge = open("merged.txt",'w')
> merge.write("Species,  Locus_Tag,  E_value,  Length, Start/Stop\n")
> 
> for line in one:
>  print(line.rstrip() + two.readline().strip())
>  merge.write(str([line.rstrip() + two.readline().strip()]))
>  merge.write("\n")
> merge.close()
> 
> inc = file("merged.txt","r")
> outc = open("final_merge.txt","w")
> for line in inc:
> line = line.replace('[','')
> line = line.replace(']','')
> line = line.replace('{','')
> line = line.replace('}','')
> outc.write(line)
> 
> inc.close()
> outc.close()
> one.close()
> two.close()
> 
> This does merge the files.
> Streptomyces sp. AA4, ZP_05482482, 2.82936001e-140,
> 5256,ZP_05482482, StAA4_010100030484,
> complement(NZ_ACEV0178.1:25146..40916) Streptomyces sp. AA4,
> ZP_05482482, 8.03332997e-138, 5256,ZP_05477599,
> StAA4_01015861, NZ_ACEV0113.1:86730..102047
> 
> But file one has multiple instances of the same Protein ID such as
> ZP_05482482. So the data doesn't line up anymore.  I would like the
> program to search for each Protein ID number and write the entry from
> file 2 in each place and then move on to the next ID number.
> 
> Example of desired output:
> Streptomyces sp. AA4, ZP_05482482, StAA4_010100030484,
> 2.82936001e-140, 5256,
> complement(NZ_ACEV0178.1:25146..40916) Streptomyces sp. AA4,
> ZP_05482482, StAA4_010100030484, 8.03332997e-138, 5256,
> complement(NZ_ACEV0178.1:25146..40916)
> 
> I was thinking about writing the text files into a dictionary and then
> searching for each ID and then insert the content from file TWO into
> where the IDs match. But I am not sure how to start. Is there a more
> pythony way to go about doing this?
> 
> Thank you for your time and help.
> 
> Regards,
> Ara

Why don't you try using the csv library which is part of the standard 
python library to parse you files.  It allows simple and efficient 
manipulation of comma separated value files.

-Rob Jackiewicz

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


Re: [Tutor] connect through the ip sharers

2010-10-25 Thread Robert Berman
Hi,

 

Since your post appears to be discussing a networking problem rather than a 
problem with the Python language you might have far better results posting to a 
group more attuned to network problems.

 

Good luck,

 

Robert 

 

From: tutor-bounces+bermanrl=cfl.rr@python.org 
[mailto:tutor-bounces+bermanrl=cfl.rr@python.org] On Behalf Of ???
Sent: Monday, October 25, 2010 11:54 AM
To: tutor@python.org
Subject: [Tutor] connect through the ip sharers

 

hello 

there are two computer. 

one is in here, and another is in other country.

both of two computer connected to internet by IP sharer.

I want to make program that connect both computer and send and receive data.

but my trying fails again and agian

 

it works when I try to connect each program in my computer but the other 
computer case, it fails


your little aid would be very helpful for me

thanks in advanced 

 

I've been sent similar question before but I still have no idea how to fix it 
so I submit similar question again sorry.


  _  

I am using the Free version of SPAMfighter <http://www.spamfighter.com/len> .
SPAMfighter has removed 16 of my spam emails to date.

Do you have a slow PC? <http://www.spamfighter.com/SLOW-PCfighter?cid=sigen>  
Try free scan! 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] connect through the ip sharers

2010-10-25 Thread Robert Berman
Hi,

 

As you well know networking opens a Pandora’s box of information so I tried 
using Google looking for ‘computer connectivity’ which has a wide range of 
topics. This may be a very good starting point you might wish to follow. The 
alternative is again using Google to look for ‘networking news groups’.

 

Also, when replying to information received by member(s) of a news group it is 
best to include the newsgroup when replying. Usually, hitting ‘reply to all’ 
will do the trick.

 

Hope this helps,

 

Robert

 

 

From: 김태윤 [mailto:kty1...@gmail.com] 
Sent: Monday, October 25, 2010 12:07 PM
To: Robert Berman
Subject: Re: [Tutor] connect through the ip sharers

 

could you tell me what group or mailing list is more attuned to network 
problems?

 

2010/10/26 Robert Berman 

Hi,

 

Since your post appears to be discussing a networking problem rather than a 
problem with the Python language you might have far better results posting to a 
group more attuned to network problems.

 

Good luck,

 

Robert 

 

From: tutor-bounces+bermanrl=cfl.rr@python.org 
[mailto:tutor-bounces+bermanrl <mailto:tutor-bounces%2Bbermanrl> 
=cfl.rr@python.org] On Behalf Of ???
Sent: Monday, October 25, 2010 11:54 AM
To: tutor@python.org
Subject: [Tutor] connect through the ip sharers

 

hello 

there are two computer. 

one is in here, and another is in other country.

both of two computer connected to internet by IP sharer.

I want to make program that connect both computer and send and receive data.

but my trying fails again and agian

 

it works when I try to connect each program in my computer but the other 
computer case, it fails


your little aid would be very helpful for me

thanks in advanced 

 

I've been sent similar question before but I still have no idea how to fix it 
so I submit similar question again sorry.

 

  _  

I am using the Free version of SPAMfighter <http://www.spamfighter.com/len> .
SPAMfighter has removed 16 of my spam emails to date.

Do you have a slow PC? <http://www.spamfighter.com/SLOW-PCfighter?cid=sigen>  
Try free scan! 

 


  _  

I am using the Free version of SPAMfighter <http://www.spamfighter.com/len> .
SPAMfighter has removed 16 of my spam emails to date.

Do you have a slow PC? <http://www.spamfighter.com/SLOW-PCfighter?cid=sigen>  
Try free scan! 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Summing up numbers in a file

2010-10-26 Thread Robert Berman
This certainly looks like a classroom  assignment. Please make an attempt to
solve the problem on your own. If the program fails, please copy the code you
have written and the error messages from the traceback  and someone here will
be more than happy to help you work your way through the problem.

 

Good luck,

 

Robert

 

From: tutor-bounces+bermanrl=cfl.rr@python.org
[mailto:tutor-bounces+bermanrl=cfl.rr@python.org] On Behalf Of masawudu
bature
Sent: Tuesday, October 26, 2010 4:20 PM
To: tutor@python.org
Subject: [Tutor] Summing up numbers in a file

 

How do I sum all occurrences of  a number in a file?

I have a file with a bunch of numbers, each on it's own line:

 

5
3

11
3
7
3
5
5
11
7

7

...

How do i sum them up so that the output will be ,

5 :  15

3 :   9

11:  22

7 :   21

 


  _  

I am using the Free version of SPAMfighter <http://www.spamfighter.com/len> .
SPAMfighter has removed 16 of my spam emails to date.

Do you have a slow PC? <http://www.spamfighter.com/SLOW-PCfighter?cid=sigen>
Try free scan! 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] if statement

2010-11-02 Thread Robert Berman


> -Original Message-
> From: tutor-bounces+bermanrl=cfl.rr@python.org [mailto:tutor-
> bounces+bermanrl=cfl.rr@python.org] On Behalf Of Glen Clark
> Sent: Tuesday, November 02, 2010 3:07 PM
> To: python mail list
> Subject: Re: [Tutor] if statement
> 
> sorry:
> 
> 
> confirmed = int(input("Are you happy with this? (y/n): ")
> 
> if confirmed == "y":
>for In in range(0,NumItems):
>   print(Entries[In] + ": " + str(In))
>change = int(input("Which item would you like to change: ")
>Entries[change]=str(input("Please enter a nem name: ")
> else:
> #do nothing

Whoops. Why are you trying to make the variable "confirmed" an integer rather
than a simple 'y/n' as you are asking for?

Robert Berman





--
I am using the free version of SPAMfighter.
We are a community of 7 million users fighting spam.
SPAMfighter has removed 34 of my spam emails to date.
Get the free SPAMfighter here: http://www.spamfighter.com/len

The Professional version does not have this message


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


Re: [Tutor] Advantages or disadvantages on Platform?

2010-11-04 Thread Robert Berman


> -Original Message-
> From: tutor-bounces+bermanrl=cfl.rr@python.org [mailto:tutor-
> bounces+bermanrl=cfl.rr@python.org] On Behalf Of Jorge Biquez
> Sent: Thursday, November 04, 2010 3:44 PM
> To: tutor@python.org
> Subject: [Tutor] Advantages or disadvantages on Platform?
> 
> Hello all.
> 
> I am newbie and studying and working hard learning python. Per your
> advise I am on 2.7 . I have one question for you.
> 
> I can work on Windows (XP) or under Ubuntu .
> 
> Do you see any advantages or disadvantanges to be working in one or
> another ?

Do you see any reasons for not working in both environments?

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


--
I am using the free version of SPAMfighter.
We are a community of 7 million users fighting spam.
SPAMfighter has removed 34 of my spam emails to date.
Get the free SPAMfighter here: http://www.spamfighter.com/len

The Professional version does not have this message


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


Re: [Tutor] While Loops: Coin Flip Game

2010-11-14 Thread Robert Berman
From: tutor-bounces+bermanrl=cfl.rr@python.org
[mailto:tutor-bounces+bermanrl=cfl.rr@python.org] On Behalf Of Dawn Samson
Sent: Sunday, November 14, 2010 5:17 PM
To: tutor@python.org
Subject: [Tutor] While Loops: Coin Flip Game
>>>>
Greetings,

I'm a Python beginner and working my way through Michael Dawson's Python
Programming for the Absolute Beginner
import random

# set the coin
coin = random.randrange(2)
headsCount = 0
tailsCount = 0
count = 0

# the loop
while count <= 100:
    coin
    if coin == 0:
        headsCount += 1
    if coin == 1:
        tailsCount += 1
    count += 1

    
print "The number of heads was", heads
print "The number of tails was", tails

raw_input("\n\nPress the enter key to exit.")

Thanks,
S. Dawn Samson
>>>>>

Hi,

Think in terms of logical steps. You need to generate the results of a random
coin toss for every toss of the coin. Therefore, if you are tossing 100
tosses, you need to generate 100 results based on a probability of zero or
one.

Since this is your homework assignment you write the code, but in terms of a
logical frame work you would have something like the following.
Tossknt = 1
Generate a random toss ; results being either one or 0. Further , assume 0 is
tail; heads is one.
If toss = 1 headcount = headcount + 1
Else tailcount = tailcount + 1
Tossknt = Tossknt + 1
If Tossknt < 100 Continue loop
Else print ‘nbr of heads tossed = ‘, headcount
Print ‘nbr of tails tossed = ‘, tailcount

Obviously, this is not valid python code but it should give you enough
information to solve your problem.

Good luck,

Robert


--
I am using the free version of SPAMfighter.
We are a community of 7 million users fighting spam.
SPAMfighter has removed 53 of my spam emails to date.
Get the free SPAMfighter here: http://www.spamfighter.com/len

The Professional version does not have this message


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


[Tutor] Help regarding lists, dictionaries and tuples

2010-11-21 Thread Robert Sjöblom
Hi. I'm new at programming and, as some others on this list, am going
through Python Programming for the Absolute Beginner. In the current
chapter (dealing with lists and dictionaries), one of the challenges
is to:
>Write a Character Creator program for a role-playing game. The player should 
>be given a pool of 30 points to spend on four attributes: Strength, Health, 
>Wisdom, and Dexterity. The >player should be able to spend points from the 
>pool on any attribute and should also be able to take points from an attribute 
>and put them back into the pool.

I don't want a direct answer on how to proceed, but a question that
arose during my thinking of the problem was whether dictionaries can
have integral data in them, like so:
attributes = {"Strength" : 28, "Health" : 12}
or if they have to be:
attributes = {"Strength" : "28", "Health" : "12"}

Ok, I'm clearly thinking in circles here. I used the interpreter to
figure out that both are fine but the first example has integers,
whereas the second has strings. Good to know. What I'm wondering then,
instead, is whether there's a good way to sum up the value of integral
data in a dictionary?

I suppose I could solve the challenge by setting up 4 different
variables and going at it that way, but since the challenge is listed
in a chapter dealing with Lists and Dictionaries (and tuples), I
figure there should be some way to solve it with those tools.

In a somewhat related note: the book gives quite hard challenges, the
coin flip challenge discussed here a few days ago, for example, comes
before the reader learns about for loops.

Thanks in advance, and best regards,
Robert S.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help regarding lists, dictionaries and tuples

2010-11-21 Thread Robert Sjöblom
[Snip]
>> I don't want a direct answer on how to proceed, but a question that
>> arose during my thinking of the problem was whether dictionaries can
>> have integral data in them, like so:
>> attributes = {"Strength" : 28, "Health" : 12}
>> or if they have to be:
>> attributes = {"Strength" : "28", "Health" : "12"}
>>
>> Ok, I'm clearly thinking in circles here. I used the interpreter to
>> figure out that both are fine but the first example has integers,
>> whereas the second has strings. Good to know. What I'm wondering then,
>> instead, is whether there's a good way to sum up the value of integral
>> data in a dictionary?
>>
>
> I will point you toward two things. First, the dict class has a method
> called values(). Read the documentation on that, go into your
> interpreter, make some dictionaries, and call the values() method, see
> what comes up.
>
> The second thing is the sum() method. Again, read the documentation on
> it and experiment with it a little. Those two should suffice to answer
> your question.
They did indeed! I did run across values() before sending the message,
but didn't quite get it to work properly -- reading up on it, I
figured out that I've been calling the method completely wrong.

> I always encourage people to play around with their problems in the
> interactive interpreter, discovering what works and what doesn't for
> yourself is often a great way to learn. Combine that with
> http://docs.python.org and you've got some very powerful learning
> tools
Yeah, using the interpreter is very helpful, I've found. I find that
even if I've studied something in the documentation, I need to use the
interpreter to figure out how it actually works. Maybe that will get
better in time, but for now it's a very useful tool in
trial-and-error. I had to try out values() and sum() before I could
understand them fully.

Thanks again, much appreciated.

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


Re: [Tutor] Help regarding lists, dictionaries and tuples (bob gailer)

2010-11-23 Thread Robert Sjöblom
On Mon, Nov 22, 2010 at 10:27 AM,   wrote:
> Send Tutor mailing list submissions to
>        tu...@python.org
>
[snip]
>> Ok, I'm clearly thinking in circles here. I used the interpreter to
>> figure out that both are fine but the first example has integers,
>> whereas the second has strings. Good to know. What I'm wondering then,
>> instead, is whether there's a good way to sum up the value of integral
>> data in a dictionary?
>
> Why would you want to sum them? You start with 30 points in the pool,
> then allocate them to the attributes. The sum will still be 30.
> Bob Gailer

Because the user should be able to spend 30 points, or remove points
from an attribute and get them back in the pool. Like so:

attributes { "Strength" : 0, "Health" : 0, "Wisdom" : 0, "Dexterity" : 0)
points = 30 - sum(attributes.values())

Or is there a better way to achieve the same result?

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


Re: [Tutor] Reply All Dilemma of This List

2009-02-10 Thread Robert Berman




Mozilla Thunderbird  version 2.0.0.19 (20090105)
running under Ubuntu Linux 8.10 does not have  "Reply to Group". Even
if it did, out of habit I would be hitting the "Reply All" button. Old
preferences die hard.

Robert

spir wrote:

  Le Tue, 10 Feb 2009 12:20:51 -0500,
Brian Mathis  a écrit :

  
  
This war has been raging since the dawn of mailing lists, and you're
not likely to get a resolution now either.

  
  
Newer mail user agents have a "to list" reply button. End of war?

--
la vida e estranya
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
  



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


Re: [Tutor] Add readline capabilities to a Python build 2.6 on Ubuntu

2009-02-19 Thread Robert Berman




Eric,

I am running under Ubuntu 8.10. 

If I use IDLE the up arrow key gives me nothing at all. It does work
using iPython which for most testing of ideas and code snippets has
replaced IDLE.

My GUI of choice is WING-personal which cost  $30.00 and is by far the
best investment I have made for a  very high powered python developing
environment and yes of course the open arrow works in that environment
also. 

Consider, at the least, using iPython.

Good luck,



Robert Berman



Eric Dorsey wrote:
Still doesnt work.. I just get this when I hit the up
arrow:
  >>> ^[[A
  
  
  Bah. It works in the 2.5 version that came packaged with it.
Thanks for trying :)
  
  
  On Wed, Feb 18, 2009 at 11:27 PM, زياد بن
عبدالعزيز الباتلي <ziyad.alba...@gmail.com>
wrote:
  On
Wed, 18 Feb 2009 20:19:56 -0700
Eric Dorsey <dors...@gmail.com> wrote:

> I did an aptitute install of
 ibreadline5-dev and then
> did ./configure and make again, and still don't have any
> functionality to be able to hit up-arrow and get a command repeated
> while inside the interpreter. Any ideas?
>
>

I don't know what's wrong, Python should pickup "libreadline" and use
it automatically if it was installed.

Try passing "--with-readline" to the "configure" script.

If that doesn't help, then I'm sorry, I'm out of ideas.

Hope that help.
Ziyad.
  
  
  
  
  
  

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



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


Re: [Tutor] String to list conversion

2009-02-24 Thread Robert Berman




Or, you could do:

In [1]: print list(raw_input('name please...'))
name please...John
['J', 'o', 'h', 'n']

Robert Berman




Kent Johnson wrote:

  On Tue, Feb 24, 2009 at 10:16 AM, Taylan Karaman
 wrote:
  
  
Hello,

I am a beginner. And I am trying to get a user input converted to a list.

print 'Enter your first name :'
firstname = raw_input()

So if the user input is

firstname = 'foo'    --->should become>
firstlist['f','o','o']

  
  
Strings behave as sequences of characters, so you can just do
firstname = 'foo'
firstlist = list(firstname)

If you just want to iterate over the letters, there is no need to
create a separate list, you can iterate over the string directly, e.g.
for letter in firstname:
  print letter

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

  



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


Re: [Tutor] Linear Algebra weirdness

2009-02-26 Thread Robert Berman




Hi,

I didn't get nearly as far as you.

In [2]: from LinearAlgebra import *
---
ImportError   Traceback (most recent call
last)

/home/bermanrl/ in ()

ImportError: No module named LinearAlgebra

In [3]: 

I am running Ubuntu Linux. What OS are yiou running and what version of
Python?


Robert Berman



Mr Gerard Kelly wrote:

  I am getting some very strange behaviour from the Linear Algebra module.

Look at this code:

from LinearAlgebra import *

a=5
print a

And look at the output that I get when I run it:

50.0
0.0
0.25
0.0
0.5
0.0
0.75
0.0
1.0
[[  2.5000e-01  -2.5000e-01  -4.3750e-01 ...,
3.73459082e+01   3.75116710e+01   3.76764961e+01]
 [  5.e-01  -5.e-01  -6.2500e-06 ...,
   -4.3797e-01  -2.49373966e-03   4.3766e-01]
 [  7.5000e-01  -7.5000e-01   0.e+00 ...,
   -7.5000e-01   0.e+00   7.5000e-01]
 [  1.e+00  -1.e+00   0.e+00 ...,
   -1.e+00   0.e+00   1.e+00]]
5


Apparently Linear Algebra is giving me the output of another program along with the output for this one. Of course I don't need Linear Algebra to print the number 5, but I've been trying to make a program that uses Linear Algebra, and I'm always having the output come out twice each time I run it. When I edit the program, it always gives me the old output before the new output, even if I edit it right down to something as simple as "a=5, print a".

Is anybody familiar with this module and why it is doing this? I've used it before and never had this issue.

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

  



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


[Tutor] Gtk time control and Glade

2009-03-17 Thread Robert Berman
I am writing a Blood-Glucose Analysis application for Diabetics. I am 
using Python 2.5 under Ubuntu 8.10 and Glade 3.4.5.


Manually recorded test results require a calendar control for the date 
of the test (no problem) and a timer control for the time of the 
test(big problem). While Glade certainly supports a calender control 
with a great deal of documentation, there is not an available time 
control for Glade. Nor was I able to find a general time control for 
Gtk. I did find one for wxwidgets but I am not using wxwidgets nor am I 
using PyQt.


I am reasonably sure such a control exists. I know I'm not the only 
individual who needs date and time controls. But, using Google has 
provided all kinds of information, there has not been a specific 
statement about any specific controls. At this time I do not feel I have 
the level of expertise to build my own control and it is something I 
would rather not have to do.


Have any of you heard of such an available time control specifically for 
Gtk and available or capable of being used by Glade.


Thank you for any insights and suggestions.


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


Re: [Tutor] Gtk time control and Glade

2009-03-17 Thread Robert Berman

Thank you Chris, that will certainly get me started.

Robert

Chris Fuller wrote:
Make your own.  You can have empty containers in glade that you fill in at 
runtime, or you could create the interface in glade, perhaps a couple of 
ComboBoxes.  I would leave an empty container and create a reusable widget 
descended from gtk.HBox that implements validation or anything else that it 
would need to do.  Maybe it could default to the current time, for instance.


I know its possible to configure glade to use custom widgets, but I've never 
bothered to learn about since it's so easy (and free of caveats that I might 
become subject to) to leave empty space for runtime use.


Here's a quick and dirty (and untested!) example:

class TimeEntry(gtk.HBox):
def __init__(self):
gtk.HBox.__init__(self)

self.hr = \
w = gtk.ComboBox()

for i in range(24):
w.append_text('%02d'%(i,))

self.pack_start(w, False, False, 0)
w.show()

w = gtk.Label(':')
self.pack_start(w, False, False, 0)
w.show()

self.min = \
w = gtk.ComboBox()

for i in range(60):
w.append_text('%02d'%(i,))

self.pack_start(w, False, False, 0)
w.show()

def get(self):
return '%02d:%02d' % (self.hr.get_active(),self.min.get_active())

Cheers

On Tuesday 17 March 2009 09:25, Robert Berman wrote:
  

I am writing a Blood-Glucose Analysis application for Diabetics. I am
using Python 2.5 under Ubuntu 8.10 and Glade 3.4.5.

Manually recorded test results require a calendar control for the date
of the test (no problem) and a timer control for the time of the
test(big problem). While Glade certainly supports a calender control
with a great deal of documentation, there is not an available time
control for Glade. Nor was I able to find a general time control for
Gtk. I did find one for wxwidgets but I am not using wxwidgets nor am I
using PyQt.

I am reasonably sure such a control exists. I know I'm not the only
individual who needs date and time controls. But, using Google has
provided all kinds of information, there has not been a specific
statement about any specific controls. At this time I do not feel I have
the level of expertise to build my own control and it is something I
would rather not have to do.

Have any of you heard of such an available time control specifically for
Gtk and available or capable of being used by Glade.

Thank you for any insights and suggestions.


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


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

  

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


Re: [Tutor] Executing a C Program from RH Linux in Python for Win

2009-03-18 Thread Robert Berman

Wayne,

I think I do the opposite of what you are doing. I develop in Python on 
a Linux (Ubuntu 8.10) box. On that box, I also run a virtual copy of 
Windows XP in its own little happy environment. That way, when my XP 
customers have a problem, I drop into the desktop environment running XP 
and we are off and running.


From the gist of your comment, you want to run Linux from within your 
Windows OS? Well, given the miracle of Virtual Memory, you can do that. 
Download the Xvm Virtual Memory (free) package from Sun and install it 
on your Windows system. Then, allocate a Linux system under the auspices 
of VM and you are off and running.


Hope this is of some help.

Robert Berman


Wayne Watson wrote:
The Subject contains the interest here. Can it be done? I think it 
this case it requires executing the program command line with 
parameters then executing it? How dependent upon the C compiled code 
is this? That is, I would think various distributions of Linux might 
produce different executable code. The too I would want to do this in 
Win. Is there, in fact, some Linux environment in Win that would allow 
me to test its executable?

--
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)


“Life is one damn thing after another."
 -- Mark Twain 
  



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

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


Re: [Tutor] Posting to Tkinter NG in new.gmane.org

2009-03-26 Thread Robert Berman
Is this a news group or a list group. If it is a news group, you can't 
use your regular email. I use T-Bird and to subscribe to 'news groups' 
you must have access to a news group server. If you look under the news 
properties under servers, you must provide a news group server (NNTP). 
Your email server(usually POP) will not work.


Robert Berman

Alan Gauld wrote:


"Wayne Watson"  wrote



   My e-mail address is valid. Any ideas? I've compacted related 
Trash folders, etc



 It should be news.gmane.org... Or is that just a typo?


In that case you probably need to tell us more.
Can you read the group OK in TBird?

What other settings are you using?
I can't help much as I don't use TBird...

Alan G

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


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


[Tutor] PDF to text conversion

2009-04-21 Thread Robert Berman

Hi,

I must convert a history file in PDF format that goes from May of 1988 
to current date.  Readings are taken twice weekly and consist of the 
date taken mm/dd/yy and the results appearing as a 10 character numeric 
+ special characters sequence. This is obviously an easy setup for a 
very small database  application with the date as the key, the result 
string as the data.


My problem is converting the PDF file into a text file which I can then 
read and process. I do not see any free python libraries having this 
capacity. I did see a PDFPILOT program for Windows but this application 
is being developed on Linux and should also run on Windows; so I do not 
want to incorporate a Windows only application.


I do not think i am breaking any new frontiers with this application. 
Have any of you worked with such a library, or do you know of one or two 
I can download and work with? Hopefully, they have reasonable 
documentation.


My development environment is:

Python
Linux
Ubuntu version 8.10


Thanks for any help  you might be able to offer.


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


Re: [Tutor] PDF to text conversion

2009-04-21 Thread Robert Berman

Bob,

Thank you for the quick reply. I am acquainted with that method, and 
that will certainly work to do some really serious testing; but, the 
data collection is an ongoing process and  the users are requesting that 
every month the latest entries (8) are brought into the system. What is 
rather irksome is that the output from the system cannot be changed from 
PDF to text; so obviously I am going to have to resolve the situation at 
my end.


I am envisioning a simple program that once started reads the data file, 
converts the data into text, and then sends the data to the database. 
The program doesn't care if there are 8 test results or 80,000 test 
results. That is why i am looking for a python module.


Thanks again,

Robert Berman

bob gailer wrote:

Robert Berman wrote:

Hi,

I must convert a history file in PDF format that goes from May of 
1988 to current date.  Readings are taken twice weekly and consist of 
the date taken mm/dd/yy and the results appearing as a 10 character 
numeric + special characters sequence. This is obviously an easy 
setup for a very small database  application with the date as the 
key, the result string as the data.


My problem is converting the PDF file into a text file which I can 
then read and process. I do not see any free python libraries having 
this capacity. I did see a PDFPILOT program for Windows but this 
application is being developed on Linux and should also run on 
Windows; so I do not want to incorporate a Windows only application.


I do not think i am breaking any new frontiers with this application. 
Have any of you worked with such a library, or do you know of one or 
two I can download and work with? Hopefully, they have reasonable 
documentation.


If this is a one-time conversion just use the save as text feature of 
adobe reader.




My development environment is:

Python
Linux
Ubuntu version 8.10


Thanks for any help  you might be able to offer.


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





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


Re: [Tutor] PDF to text conversion

2009-04-21 Thread Robert Berman

Hello Emad,

I have seriously looked at the documentation associated with pyPDF. This 
seems to have the page as its smallest element of work, and what i need 
is a line by line process to go from .PDF format to Text. I don't think 
pyPDF will meet my needs but thank you for bringing it to my attention.


Thanks,


Robert Berman

Emad Nawfal (عماد نوفل) wrote:



On Tue, Apr 21, 2009 at 12:54 PM, bob gailer <mailto:bgai...@gmail.com>> wrote:


Robert Berman wrote:

Hi,

I must convert a history file in PDF format that goes from May
of 1988 to current date.  Readings are taken twice weekly and
consist of the date taken mm/dd/yy and the results appearing
as a 10 character numeric + special characters sequence. This
is obviously an easy setup for a very small database
 application with the date as the key, the result string as
the data.

My problem is converting the PDF file into a text file which I
can then read and process. I do not see any free python
libraries having this capacity. I did see a PDFPILOT program
for Windows but this application is being developed on Linux
and should also run on Windows; so I do not want to
incorporate a Windows only application.

I do not think i am breaking any new frontiers with this
application. Have any of you worked with such a library, or do
you know of one or two I can download and work with?
Hopefully, they have reasonable documentation.


If this is a one-time conversion just use the save as text feature
of adobe reader.



My development environment is:

Python
Linux
Ubuntu version 8.10


Thanks for any help  you might be able to offer.


Robert Berman
___
Tutor maillist  -  Tutor@python.org <mailto:Tutor@python.org>
http://mail.python.org/mailman/listinfo/tutor



-- 
Bob Gailer

Chapel Hill NC
919-636-4239

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



I tried pyPdf once, just for fun, and it was nice:
http://pybrary.net/pyPdf/
--
لا أعرف مظلوما تواطأ الناس علي هضمه ولا زهدوا في إنصافه 
كالحقيقة.محمد الغزالي

"No victim has ever been more repressed and alienated than the truth"

Emad Soliman Nawfal
Indiana University, Bloomington


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


Re: [Tutor] PDF to text conversion

2009-04-21 Thread Robert Berman
First, thanks to everyone who contributed to this thread. I have a 
number of possible solutions and a number of paths to pursue to 
determine which avenue I should take to resolve this remaining issue. I 
did try the itools library and while everything installed nicely, most 
of the tests failed so I am not particularly overjoyed with the results.


Thank you Dinesh for the vote of sympathy. I do appreciate it.

I did use Adobe Reader to convert the history PDF file into a text file 
and it did seem to do it faithfully. So now I will work out a parsing 
function to extract my data and send it to a SQLLITE database.


I am thrilled both with the number of suggestions I have received from 
this group and the quality of the suggestions.


Thanks again,

Robert Berman





Norman Khine wrote:

the itools library from hforge.org has a PDF2TEXT implementation itools.pdf

http://www.hforge.org/itools

norman

On Tue, Apr 21, 2009 at 8:44 PM, Dayo Adewunmi  wrote:
  

Emile van Sebille wrote:


Robert Berman wrote:


  

Have any of you worked with such a library, or do you know of one or two
I can download and work with? Hopefully, they have reasonable documentation.

My development environment is:

Python
Linux
Ubuntu version 8.10



I've used

[r...@fcfw2 /]# /usr/bin/pdftotext -v
pdftotext version 2.01
Copyright 1996-2002 Glyph & Cog, LLC
[r...@fcfw2 /]# cat /etc/issue
Red Hat Linux release 9 (Shrike)


HTH,

Emile

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

  

Hi Robert,
pdftotext is part of poppler-utils, an Ubuntu package which can be installed
like so:

sudo aptitude install poppler-utils

But I to would be interested in finding a python library/module for this.

Regards,

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



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

  

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


Re: [Tutor] PDF to text conversion

2009-04-22 Thread Robert Berman

Dinesh,

I have pdftotext version 3.0.0.  I have decided to use this to go from 
PDF to text. It is not the ideal solution, but is is a certainly doable 
solution.


Thank you,

Robert

Dinesh B Vadhia wrote:
The best converter so far is pdftotext from 
http://www.glyphandcog.com/ who maintain an open source project at 
http://www.foolabs.com/xpdf/.
 
It's not a Python library but you can call pdftotext from with Python 
using os.system().  I used the pdftotext -layout option and that gave 
the best result.  hth.
 
dinesh
 


Message: 4
Date: Tue, 21 Apr 2009 18:37:39 -0400
From: Robert Berman mailto:berma...@cfl.rr.com>>
Subject: Re: [Tutor] PDF to text conversion
To: tutor@python.org <mailto:tutor@python.org>
Message-ID: <49ee4ab3.4040...@cfl.rr.com 
<mailto:49ee4ab3.4040...@cfl.rr.com>>

Content-Type: text/plain; charset=ISO-8859-1; format=flowed

First, thanks to everyone who contributed to this thread. I have a
number of possible solutions and a number of paths to pursue to
determine which avenue I should take to resolve this remaining issue. I
did try the itools library and while everything installed nicely, most
of the tests failed so I am not particularly overjoyed with the results.

Thank you Dinesh for the vote of sympathy. I do appreciate it.

I did use Adobe Reader to convert the history PDF file into a text file
and it did seem to do it faithfully. So now I will work out a parsing
function to extract my data and send it to a SQLLITE database.

I am thrilled both with the number of suggestions I have received from
this group and the quality of the suggestions.

Thanks again,

Robert Berman



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

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


Re: [Tutor] Number cruncher

2009-04-22 Thread Robert Berman

Hello John,

It is the general policy of the 'tutors group' to not solve homework 
problems. Given that very basic rule, there are obvious elements for 
which we can definitely give help. But, you have to take the first step 
and that is a relatively big one. You have to define an algorithm or 
recipe to solve the problem. To do so, you must define your inputs. As a 
first comment, while you did specify that each assignment is weighted, 
you gave no indication that a grade was a required input. Obviously a 
heavily weighted '88' may carry more import than a very light weight '94'.


What you need to do is define (1) Your inputs, (2) your outputs (what 
comes out of the recipe and how you want it served. ie, how displayed. 
And then, once you have defined the obvious you must resolve the heart 
of the algorithm, how do you compute the outputs.


Hopefully, while this is certainly not 'the' answer it will get you started.

Robert Berman

John Jenkinson wrote:
I need to write code that determines a students final grade based on 
the number of each type of assignment turned in with its corresponding 
weighted percentage.  There will be 15-20 inputs.  I have not reached 
this point in my learning of python, so I would like to request a 
resource that would help me for this project.
 
- John Jenkinson



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

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


Re: [Tutor] Python help

2009-04-22 Thread Robert Berman

Yes.

Show us your solution and perhaps we can help you make it a tad more 
efficient.


Robert Berman

IT_ForMe wrote:

Anyone know how to program this using Python

Add up the prices for items in a shopping cart. Some items are taxable and
some items are not. You may assume a 7% tax rate for all taxable items.
Apply a 10% discount if the customer is a student. (hint, instead of asking
the user to input items, set them up as an associative array in the code)
  

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


Re: [Tutor] Lists in a file

2009-04-26 Thread Robert Berman

David,

You are processing a text file. It is your job to treat it as a file 
comprised of lists. I think what you are saying is that each line in the 
text file is a list. In that case


for line in fileobject:
   listline = list(line)

Now, listline is a list of the text items in line.

Hope this helps.

Robert Berman

David Holland wrote:

Hi,

I am trying to create a program where I open a file full of lists and 
process them.

However when the program does not recognize the lists as lists.
Here is the relevant code :-
def open_filedef():
text_file =open ("voteinp.txt","r")
lines = text_file.readlines()
   
   
for line in lines:

print line
print line[0]
 
text_file.close()


And an example of the type of text :-

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

Any ideas?


Thanks in advance


David Holland




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

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


[Tutor] Different Command Result Executing in Shell vs. Program

2009-05-09 Thread robert mcquirt

  
  
  
  
  
  
   
  
 
  
   Hi. I've not been working with Python very long and have run into a puzzling 
thing. I'm working on a program that needs to identify the filetype of files 
without extensions. Using the file command in the shell works fantastic, as in:
   
   
rob...@ubuntu:~$ file -b linuxlogotag
   JPEG image data, JFIF standard 1.01
   
   
I want to be able to perform the same task in a program for batch processing. 
After a bit of research, I found that I can execute the shell command from 
within a Python program using:
   
   
import os
   os.system('file -b /home/robert/linuxlogotag')
   
   
This also works fine. The problem is that when I try to replace the hard coded 
path/name with a string variable for looping, the results are not the same as 
the shell's. Here's the modified code I'm using for testing (the original code 
is from Bogdan's blog at http://bogdan.org.ua/).
   
   
import os, glob
   path = '/home/robert'
   for infile in glob.glob( os.path.join(path, '*.*') ):
 testCommand = "'file -b " + infile + "'"
 print testCommand,
 test = os.system(testCommand)
 print test
   
   
The code does indeed step through all the files in the directory and the 
testCommand string constructs properly. Yet, the output is not the same as 
shell results. All files, regardless of type, simply output the number 32512, 
with no description.

   
   I have searched forums, read the man file and perused several Python 
references and have not been able to find the answer. Why does the same command 
yield different results, depending on how it's run? Any education is greatly 
appreciated.

   
   Linux 2.6 (kubuntu 8.04)
   Python 2.5.2
   file command 4.21
  


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


Re: [Tutor] Different Command Result Executing in Shell vs. Program

2009-05-10 Thread robert mcquirt
@alan: Thank you very much for the information you provided and also for 
suggesting your tutorial. I am now studying the subprocess module. I was 
impressed with the depth of your tutorial and am studying it as well (and not 
just for my current problem). Thanks again.

@dave: Thanks for your reply Dave. I did try removing the quote as you 
suggested and then received an error of missing quote. As best I can determine 
the quotes are needed to surround the command being used in the os.system() 
context. However, your reply did serve to remind me to check the simple 
possibilities first before seeking a more involved solution. Thanks again for 
that.  



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


[Tutor] Iterating over list of functions

2009-05-20 Thread Robert Berman
Hi,

Given a list of options: option_1...option_n. For each option I have
a corresponding function: func_1. func_n. I have all function names
defined in a list similar to flist = [func_1, func_2,...func_n]
which I know is a legitimate construct having found a similar  construct
discussed by Kent Johnson in 2005.

What I do not know how to do is to call the selected function. If the
index of options is 1, then I want to call func_2; do I code
flist[index]? I do not think Python has a branch indirect construct so I
cannot use anything similar to that methodology.  What is the best
approach to take to solve this problem?

Thank you for any assistance, hints, solutions, and guidelines.

Robert




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


Re: [Tutor] Iterating over list of functions

2009-05-20 Thread Robert Berman
Thank you, Emile.

That is the exact answer I needed.

Robert


On Wed, 2009-05-20 at 07:48 -0700, Emile van Sebille wrote:

> On 5/20/2009 7:25 AM Robert Berman said...
> > Hi,
> > 
> > Given a list of options: option_1...option_n. For each option I have
> > a corresponding function: func_1. func_n. I have all function names
> > defined in a list similar to flist = [func_1, func_2,...func_n]
> > which I know is a legitimate construct having found a similar  construct
> > discussed by Kent Johnson in 2005.
> > 
> > What I do not know how to do is to call the selected function. If the
> > index of options is 1, then I want to call func_2; do I code
> > flist[index]?
> 
> Yes - with trailing () of course...
> 
> def func1():return 1
> def func2():return 2
> def func3():return 3
> flist = [func1,func2,func3]
> flist[0]()
> flist[1]()
> flist[2]()
> 
> Emile
> 
> 
>   I do not think Python has a branch indirect construct so I
> > cannot use anything similar to that methodology.  What is the best
> > approach to take to solve this problem?
> > 
> > Thank you for any assistance, hints, solutions, and guidelines.
> > 
> > Robert
> > 
> > 
> > 
> > 
> > ___
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
> > 
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Iterating over list of functions

2009-05-20 Thread Robert Berman
Thank you, Christian. This solution was one I was not expecting and am
glad to receive it. It is one I will explore in greater detail later.

Robert


On Wed, 2009-05-20 at 16:44 +0200, Christian Witts wrote:
> Robert Berman wrote:
> > Hi,
> >
> > Given a list of options: option_1...option_n. For each option I have
> > a corresponding function: func_1. func_n. I have all function names
> > defined in a list similar to flist = [func_1, func_2,...func_n]
> > which I know is a legitimate construct having found a similar  construct
> > discussed by Kent Johnson in 2005.
> >
> > What I do not know how to do is to call the selected function. If the
> > index of options is 1, then I want to call func_2; do I code
> > flist[index]? I do not think Python has a branch indirect construct so I
> > cannot use anything similar to that methodology.  What is the best
> > approach to take to solve this problem?
> >
> > Thank you for any assistance, hints, solutions, and guidelines.
> >
> > Robert
> >
> >
> >
> >
> > ___
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
> >   
> Why not use a dictionary to do the heavy lifting for you
> 
>  >>> import string
>  >>> funcs = {1:string.upper, 2:string.lower}
>  >>> funcs[1]('this is a simple test')
> 'THIS IS A SIMPLE TEST'
>  >>> funcs[2]('THIS IS A SIMPLE TEST')
> 'this is a simple test'
> 

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


[Tutor] Iterating through a function list

2009-05-20 Thread Robert Berman
Hi,

Given a list of options: option_1...option_n. For each option I have
a corresponding function: func_1. func_n. I have all function names
defined in a list similar to flist = [func_1, func_2,...func_n]
which I know is a legitimate construct having found a similar  construct
discussed by Kent Johnson in 2005.

What I do not know how to do is to call the selected function. If the
index of options is 1, then I want to call func_2; do I code
flist[index]? I do not think Python has a branch indirect construct so I
cannot use anything similar to that methodology.  What is the best
approach to take to solve this problem?

Thank you for any assistance, hints, solutions, and guidelines.

Robert

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


Re: [Tutor] Iterating over list of functions

2009-05-20 Thread Robert Berman
Alan,

The emphasis of your reply certainly makes me look at the dictionary
solution as the most 'correct' solution to utilize. Before I change the
code I just implemented, let me make sure I understand exactly what you
are saying and what you are advocating. The 'dictionary of functions' is
the 'best' approach because of simplicity and because it minimizes
chances or errors. The one area you did not address is the area of
efficiency. Is this method also the most efficient solution?

The reason I am trying to pin you are two fold. First, you are a
powerful spokesman for 'correct and proper' coding in the Python
community and I take  your opinions and commentaries seriously. Again,
how efficient is this method and is it truly the 'most pythonesque'
oriented code.

Thanks again,

Robert


On Wed, 2009-05-20 at 16:07 +0100, Alan Gauld wrote:

> "Robert Berman"  wrote
> 
> > Thank you, Christian. This solution was one I was not expecting and am
> > glad to receive it. It is one I will explore in greater detail later.
> 
> A dictionary of functions is the most common way to tackle 
> this fairly common requirement. It combines readability with 
> ease of maintenance, there is no chance of using the wrong 
> index.
> 
> >> Why not use a dictionary to do the heavy lifting for you
> >> 
> >>  >>> import string
> >>  >>> funcs = {1:string.upper, 2:string.lower}
> >>  >>> funcs[1]('this is a simple test')
> >> 'THIS IS A SIMPLE TEST'
> >>  >>> funcs[2]('THIS IS A SIMPLE TEST')
> >> 'this is a simple test'
> 
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Need help solving this problem

2009-06-10 Thread Robert Berman
What you are looking at is a simulation whereby a coin having 2 outcomes
(heads or tails) is flipped exactly 100 times. You need to tell how many
times the coin falls heads up and how many times the coin falls tails
up. 

First become familiar with the random module. Assign a value of 1 for
heads and a value of 2 for tails. Then you are going to use a structure
of the random module which will return only two possible outcomes.
Either a one or a two. You are going to loop (look at range(1,101) or
range(0,100). (Side question; why 101 or 0 to 100?; look closely at the
meaning of the range arguments). Simply count the number of ones and the
number of two's in the 100 flips then print the results. 

Good luck.

Robert


On Wed, 2009-06-10 at 13:08 -0700, Raj Medhekar wrote:
> I have been teaching myself Python using a book. The chapter I am on
> currently, covers branching, while loops and program planning. I am
> stuck on on of the challenges at the end of this chapter, and I was
> hoping to get some help with this. Here it is:
> 
> Write a program that flips a coin 100 times and the tells you the
> number of heads and tails.
> 
> I have tried to think about several ways to go about doing this but I
> have hit a wall. Even though I understand the general concept of
> branching and looping, I have been having trouble writing a program
> with these.  I look forward to your reply that will help me understand
> these structures better.
> 
> Sincerely,
> Raj
> 
> 
> 
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] How do I do this in python?

2009-06-11 Thread Robert Lummis
I want to write a function that I can use for debugging purposes that
prints the values of whatever list of object references it is given as
arguments, without knowing in advance how many object references it
will be called with or what they might be. For example, the call:
show(a,b,c) would output the values of the arguments like this:

a = 3
b = 'john'
c = 'Monday'

while show (x) would output (for example):

x = 3.14

of course displaying whatever the actual current values are. For a
collection object it would make sense to output just the first few
values.

So within the 'show' function definition I have to somehow get a list
of the literal argument names it was called with and then use the
names as globals to get the values. How do I do that?

If this can't be done but there is a completely different way to
achieve a similar result, what is it?

I'm trying to learn python but it's a struggle because the
documentation is so dispersed. If there is a solution to this
question, what documentation could I have looked at to find it on my
own?

BTW I'm using python 3.01 if it matters.

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


Re: [Tutor] How do I do this in python?

2009-06-11 Thread Robert Lummis
On Thu, Jun 11, 2009 at 11:58 AM, spir wrote:
> Le Thu, 11 Jun 2009 10:46:26 -0400,
> Kent Johnson  s'exprima ainsi:
>
>> On Wed, Jun 10, 2009 at 9:43 PM, Robert Lummis
>> wrote:
>> > I want to write a function that I can use for debugging purposes that
>> > prints the values of whatever list of object references it is given as
>> > arguments, without knowing in advance how many object references it
>> > will be called with or what they might be. For example, the call:
>> > show(a,b,c) would output the values of the arguments like this:
>> >
>> >    a = 3
>> >    b = 'john'
>> >    c = 'Monday'
>> >
>> > while show (x) would output (for example):
>> >
>> >    x = 3.14
>>
>> Here is a pretty clean solution. It passes names rather than values,
>> then looks the values up in the caller's stack frame. Written for
>> Python 2.x but should work for 3.x if you change the prints.
>>
>> In [1]: import sys
>> In [11]: def show(names):
>>    :     frame = sys._getframe(1)
>>    :     for name in names.split():
>>    :         if name in frame.f_locals:
>>    :             print name, '=', frame.f_locals[name]
>>    :         else:
>>    :             print name, 'not found'
>>
> [...]
>>
>> Kent
>
> Waow, great!
>
> Denis
> --
> la vita e estrany
> ___
> Tutor maillist  -  tu...@python.org
> http://mail.python.org/mailman/listinfo/tutor
>

Thanks for all the intelligent and thoughtful replies to my newB
question. It looks like this tutor mailing list is going to be a big
help!  It's going to take me some time and trial and error to digest
all the replies so I understand them fully but it will be instructive.

I guess one thing I learned already, even though I didn't ask about
it, is that using python3 isn't the best way to start out.

Again, thank you all for taking the time to reply.
-- 
Robert Lummis
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help Needed

2009-06-16 Thread Robert Berman
You are putting far too much work into the solution. Look up slicing on
the python web page. Then, as an example,


In [1]: s1 = 'hello world'

In [2]: s1[::-1]
Out[2]: 'dlrow olleh'

Hope this helps,

Robert

On Tue, 2009-06-16 at 14:25 -0700, Raj Medhekar wrote:
> I had previously emailed y'all regarding inverting a message input by
> the user of the program backwards. After much contemplation on your
> earlier replies I came up with the code I have included in this email.
> The problem I am having with this code is that the the first character
> of the message that is reversed does not come up. Is there a solution
> to this? For my message that I input I used "take this" to test it,
> use the same message when the program prompts you to enter the message
> and run it, you'll see what I mean. Also is there a way to say reverse
> the string in a way so the reversed string would result to "this take"
> if you use my example? And is there a way to stop the loop without the
> use of break? Thanks for the help!
> 
> Peace,
> Raj
> 
> My Code:
> 
> # Backward message
> # program gets message from user then prints it out backwards
> 
> message = raw_input("Enter your message: ")
> 
> print message
> 
> high = len(message)
> low = -len(message)
> 
> begin=None
> while begin != "":
> begin = int(high)
> 
> if begin:
> end = int(low)
> 
> print "Your message backwards is",
> print message[begin:end:-1]
> break
> 
> 
> raw_input("\n\nPress the enter key to exit")
> 
> 
> 
> 
> 
> 
> 
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] List Splicing

2009-06-17 Thread Robert Berman
Greetings,

I am working on a 'simple' algorithm to solve the problem called PRIME1
explained at http://www.spoj.pl/problems/PRIME1/. 

I do have an algorithm based on the Sieve of Eratosthenes and it does
work as I am failing the project not because of a computational error
but because of the dreaded TLE (time limit exceeded) designator. I have
determined there are at least 3 areas for improvement. The first is
within my code where I am creating a list of the first million primes. 
The code is as follows:

def BuildSieve(itemsin):
TheSieve=list()
TheSieve = range(0,itemsin+1)
TheSieve[1]=0
for i in range(2,itemsin+1):
if (TheSieve[i] > 0):
j = i + i
while (j <= itemsin):
TheSieve[j] = 0
j+=i
return TheSieve

It is called with PrimaryList = BuildSieve(100)

I have read that list splicing rather than looping to set a range of
items to zero is the best approach. Given an example  list  of

In [53]: l1
Out[53]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]

Since 3 is a prime, we can eliminate all multiples of 3. Within l1,
these are expressed as

In [52]: l1[n+n:len(l1):n]
Out[52]: [6, 9, 12]

when n = 3. ( do know 12 would have been eliminated by the prime number
2)

It would be great if I could say l1[n+n:len(l1):n] = 0 but obviously
that will fail for obvious reasons. I am looking for the right hand side
of the statement to set a list within the list to all zeros. Also, if
anyone had a relatively simple explanation why in Python this is faster
than a loop, I would really like to understand it.

Thanks for the input.

Robert



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


Re: [Tutor] List Splicing

2009-06-17 Thread Robert Berman
Emile,

Thank your for your comments. I do have a list running from 0-101.
Yes, it is true, I only needed 0 - 10 and yes I will change it.
However, if you use primearray as a sieve of all primes 2-100 you
will see it works quite well. Printing a range, say primearray[21]
through primearray[50] will give you all prime numbers between 21 and
50.

23
29
31
37
41
43
47

73000 to 99,123 works nicely, too. I did, in the beginning use a list of
100 (actually (101) and that worked well so thank you for corroborating
the approach.

Another question I will ask after this one is resolved involves the
methodology I use to find primes well over one million.

However, for the time being, can you perhaps share some suggestions on
list splicing?

Thank you for your assistance.

Robert




On Wed, 2009-06-17 at 15:25 -0700, Emile van Sebille wrote:
> On 6/17/2009 3:03 PM Robert Berman said...
> > Greetings,
> > 
> > I am working on a 'simple' algorithm to solve the problem called PRIME1
> > explained at http://www.spoj.pl/problems/PRIME1/. 
> > 
> > I do have an algorithm based on the Sieve of Eratosthenes and it does
> > work as I am failing the project not because of a computational error
> > but because of the dreaded TLE (time limit exceeded) designator. I have
> > determined there are at least 3 areas for improvement. The first is
> > within my code where I am creating a list of the first million primes. 
> 
> It looks more like it creates a list 101 in length where the 
> non-zero numbers in that list are primes.  I'd try BuildSieve(100) until 
> BuildSieve was returning just primes.
> 
> Or, are you trying to create a list of the primes under 100?
> 
> Optimization should proceed once you've got it working.
> 
> Emie
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

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


Re: [Tutor] List Splicing

2009-06-17 Thread Robert Berman
Emille,

Thank you for the example of list splicing.  Do you know if this is
faster than a more conventional loop statement as in my code for
primearray which is in my original post (reprinted here)

The code is as follows:

def BuildSieve(itemsin):
TheSieve=list()
TheSieve = range(0,itemsin+1)
TheSieve[1]=0
for i in range(2,itemsin+1):
if (TheSieve[i] > 0):
j = i + i
while (j <= itemsin):
TheSieve[j] = 0
j+=i
return TheSieve

It is called with PrimaryList = BuildSieve(100)

Again, thank you for your help.

Robert


On Wed, 2009-06-17 at 17:01 -0700, Emile van Sebille wrote:

> On 6/17/2009 4:48 PM Robert Berman said...
> > Emile,
> > 
> > Thank your for your comments. I do have a list running from 0-101.
> > Yes, it is true, I only needed 0 - 10 and yes I will change it.
> > However, if you use primearray 
> 
> you haven't posted the primearray code...
> 
> 
> > 
> > However, for the time being, can you perhaps share some suggestions on
> > list splicing?
> 
> So, this part of your original post--
>  > Out[53]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
>  >
>  > Since 3 is a prime, we can eliminate all multiples of 3. Within l1,
>  > these are expressed as
>  >
>  > In [52]: l1[n+n:len(l1):n]
>  > Out[52]: [6, 9, 12]
>  >
>  > when n = 3. ( do know 12 would have been eliminated by the prime
>  > number 2)
>  >
>  > It would be great if I could say l1[n+n:len(l1):n] = 0
> 
> but you can say:
> 
> for ii in l1[n+n:len(l1):n]: l1[ii] = 0
> 
> Is something like that what you're after?
> 
> Emile
> 
> 
> 
>  > but obviously
>  >
>  > that will fail for obvious reasons. I am looking for the right hand
>  > side of the statement to set a list within the list to all zeros.
> ---
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] List Splicing

2009-06-17 Thread Robert Berman
Wayne,

Thank you for the suggestion. I will let you know how well this plays
out.

Robert




On Wed, 2009-06-17 at 19:26 -0500, Wayne wrote:
> On Wed, Jun 17, 2009 at 7:11 PM, Robert Berman 
> wrote:
> Emille,
> 
> Thank you for the example of list splicing.  Do you know if
> this is  faster than a more conventional loop statement as in
> my code for primearray which is in my original post (reprinted
> here)
> 
> 
> The code is as follows:
> 
> def BuildSieve(itemsin):
> TheSieve=list()
> TheSieve = range(0,itemsin+1)
> TheSieve[1]=0
> for i in range(2,itemsin+1):
> if (TheSieve[i] > 0):
> j = i + i
> while (j <= itemsin):
> TheSieve[j] = 0
> j+=i
> return TheSieve
> 
> It is called with PrimaryList = BuildSieve(100)
> 
> 
> I'm curious if it wouldn't be faster to use xrange. I know for certain
> instead of range(0, itemsin+1) you could use TheSieve = [1, 2]
> TheSieve.extend(range(3, itemsin+1,2))
> 
> Which would save you at least half the time in your generation. Since
> your first step should be removing multiples of two, that should be a
> big help.
> 
> HTH,
> Wayne
> 
> 

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


Re: [Tutor] List Splicing

2009-06-17 Thread Robert Berman
Emille,

Thank you very much for the information on timeit. I will investigate
and use it.

>>... but this isn't what BuildSieve yields:

 >>> BuildSieve(20)
>>[0, 0, 2, 3, 0, 5, 0, 7, 0, 0, 0, 11, 0, 13, 0, 0, 0, 17, 0, 19, 0]

>>So I still don't know what primearray is/does.

If you look at or print all non zero numbers you have the primes between
2 and 20.

Robert


On Wed, 2009-06-17 at 17:30 -0700, Emile van Sebille wrote:

> On 6/17/2009 5:11 PM Robert Berman said...
> > Emille,
> > 
> > Thank you for the example of list splicing.  Do you know if this is  
> > faster than a more conventional loop statement
> 
> Faster can be exactly determined using timeit.  (for some definition of 
> exact -- the one we use mostly around here anyway)
> 
> So, for the bits you want to know faster about, you'd do something like:
> 
>  >>> from timeit import Timer
>  >>> t = Timer("aa = range(0,100,2)")
>  >>> t.timeit()
> 1.6688069739620928
>  >>> t = Timer("aa = range(100)[::2]")
>  >>> t.timeit()
> 3.3360306112492282
>  >>>
> 
> I'm not sure this applies specifically to what you're doing, and 
> crafting what you are timing is important, but read up on timeit and try 
> it out.
> 
> 
> > as in my code for 
> > primearray which is in my original post (reprinted here)
> 
> Well, there's the confusion.  This is the code for something called 
> BuildSieve.  In your prior post you show:
> 
> -
> Printing a range, say primearray[21]
> through primearray[50] will give you all prime numbers between 21 and
> 50.
> 
> 23
> 29
> 31
> 37
> 41
> 43
> 47
> -
> 
> ... but this isn't what BuildSieve yields:
> 
>  >>> BuildSieve(20)
> [0, 0, 2, 3, 0, 5, 0, 7, 0, 0, 0, 11, 0, 13, 0, 0, 0, 17, 0, 19, 0]
> 
> So I still don't know what primearray is/does.
> 
> Emile
> 
> > 
> > The code is as follows:
> > 
> > def BuildSieve(itemsin):
> > TheSieve=list()
> > TheSieve = range(0,itemsin+1)
> > TheSieve[1]=0
> > for i in range(2,itemsin+1):
> > if (TheSieve[i] > 0):
> > j = i + i
> > while (j <= itemsin):
> > TheSieve[j] = 0
> > j+=i
> > return TheSieve
> > 
> > It is called with PrimaryList = BuildSieve(100)
> > 
> > Again, thank you for your help.
> > 
> > Robert
> > 
> > 
> > On Wed, 2009-06-17 at 17:01 -0700, Emile van Sebille wrote:
> >> On 6/17/2009 4:48 PM Robert Berman said...
> >> > Emile,
> >> > 
> >> > Thank your for your comments. I do have a list running from 0-101.
> >> > Yes, it is true, I only needed 0 - 10 and yes I will change it.
> >> > However, if you use primearray 
> >>
> >> you haven't posted the primearray code...
> >>
> >> 
> >> > 
> >> > However, for the time being, can you perhaps share some suggestions on
> >> > list splicing?
> >>
> >> So, this part of your original post--
> >>  > Out[53]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
> >>  >
> >>  > Since 3 is a prime, we can eliminate all multiples of 3. Within l1,
> >>  > these are expressed as
> >>  >
> >>  > In [52]: l1[n+n:len(l1):n]
> >>  > Out[52]: [6, 9, 12]
> >>  >
> >>  > when n = 3. ( do know 12 would have been eliminated by the prime
> >>  > number 2)
> >>  >
> >>  > It would be great if I could say l1[n+n:len(l1):n] = 0
> >>
> >> but you can say:
> >>
> >> for ii in l1[n+n:len(l1):n]: l1[ii] = 0
> >>
> >> Is something like that what you're after?
> >>
> >> Emile
> >>
> >>
> >>
> >>  > but obviously
> >>  >
> >>  > that will fail for obvious reasons. I am looking for the right hand
> >>  > side of the statement to set a list within the list to all zeros.
> >> ---
> >>
> >> ___
> >> Tutor maillist  -  Tutor@python.org <mailto:Tutor@python.org>
> >> http://mail.python.org/mailman/listinfo/tutor
> > 
> > 
> > 
> > ___
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Eliminating consecutive duplicates in a list

2009-06-18 Thread Robert Berman
This might help: http://code.activestate.com/recipes/52560/

Robert


On Thu, 2009-06-18 at 15:15 +0200, karma wrote:
> I was playing around with eliminating duplicates in a list not using
> groupby. From the two solutions below, which is more "pythonic".
> Alternative solutions would be welcome.
> 
> Thanks
> 
> x=[1,1,1,3,2,2,2,2,4,4]
> 
> [v for i,v in enumerate(x) if x[i]!=x[i-1] or i==0]
> 
> [x[i] for i in range(len(x)-1) if i==0 or x[i]!=x[i-1]]
> 
> output:
> [1, 3, 2, 4]
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

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


Re: [Tutor] Eliminating consecutive duplicates in a list

2009-06-18 Thread Robert Berman
Whoops. That's called assuming what I read is really what I see. A good
lesson in reading questions twice.

I remember this from a post some time back and I remember having been
intrigued by it. I used Google, and since I tend to keep extensive
notes, the solution I found is not uniquely mine, but it does work.
http://wasstock.com/?p=12

Robert


On Thu, 2009-06-18 at 16:23 +0200, karma wrote:
> Hi Robert,
> 
> Thanks for the link. However, I am looking for eliminating consecutive
> duplicates rather than all duplicates - my example wasn't clear,
> apologies for that.
> 
> x=[1,1,1,3,2,2,2,4,4,2,2]
> 
> [1 ,3 ,2 ,4 ,2 ]
> 
> 
> 2009/6/18 Robert Berman :
> > This might help: http://code.activestate.com/recipes/52560/
> >
> > Robert
> >
> >
> > On Thu, 2009-06-18 at 15:15 +0200, karma wrote:
> >> I was playing around with eliminating duplicates in a list not using
> >> groupby. From the two solutions below, which is more "pythonic".
> >> Alternative solutions would be welcome.
> >>
> >> Thanks
> >>
> >> x=[1,1,1,3,2,2,2,2,4,4]
> >>
> >> [v for i,v in enumerate(x) if x[i]!=x[i-1] or i==0]
> >>
> >> [x[i] for i in range(len(x)-1) if i==0 or x[i]!=x[i-1]]
> >>
> >> output:
> >> [1, 3, 2, 4]
> >> ___
> >> Tutor maillist  -  Tutor@python.org
> >> http://mail.python.org/mailman/listinfo/tutor
> >
> >

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


[Tutor] how to manage an encrypted file?

2009-06-19 Thread Robert Lummis
Could you recommend a module or methods I should use to manage an
encrypted text file? I want to store passwords and associated contact
information in a file and feel confident that if the file is stolen
the information couldn't be read.

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


Re: [Tutor] how to manage an encrypted file?

2009-06-22 Thread Robert Lummis
Very good suggestion! Thanks! I knew about TrueCrypt before (it's
really excellent) but I didn't think of it for this purpose because it
didn't show up when I did a Synaptic search. I'll see if I can get it
installed on ubuntu and used with Python. Actually, the URL you give
doesn't work (at least for me). But I found the following by googling
the URL:

http://blog.bjrn.se/2008/02/truecrypt-explained-truecrypt-5-update.html

On Mon, Jun 22, 2009 at 3:46 AM, Daniele wrote:
>> From: Wayne 
>
>> If you want the most basic encryption you could simply XOR the file. It's 
>> fairly easy to break, though, because the same character patterns will be 
>> present as with your original file.
>
> Actually if you do it properly this kind of encryption is unbreakable,
> but you'd have to:
> 1. generate a random key long enough to cover your data
> 2. keep the key secure and in a separate place
> 3. DON'T use the key twice
>
> there must be a Security Now episode that explains the thing pretty
> well (could be this one http://www.grc.com/sn/sn-011.htm).
> Some arguments may rise against the randomness of the key, but I don't
> think its the case to go into that.
>
> You could also use TrueCrypt which is an extremely powerful
> cryptographic software (open source), I found this article that can
> help you linking it with python:
> http://blog.bjrn.se/2008/01/truecrypt-explained.html
>



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


[Tutor] does python have something like "#include" in C?

2009-06-29 Thread Robert Lummis
... or any pre-processing at all?

I'm looking for a way to get boiler plate code into the main program
file. Of course I could copy and paste it with an editor but I was
hoping for something more pythonic. I know about import but that's not
the same.

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


Re: [Tutor] does python have something like "#include" in C?

2009-06-29 Thread Robert Lummis
Here's an example that seems not possible in python. I'm probably
missing something so please enlighten me. I only tried doing this as
an exercise to show myself how name references work. I'm not saying
it's needed or that it's good practice.

I can write the following as a single file and it works as expected:

===snip===
#!/usr/bin/python

def show(*args):
print
for arg in args:
print arg + ':',
exec('print ' + arg)

a=15
b='hello'
x=['bob',3]

show('a')
show('a','b')
show('a','b','x')
===snip===

The calls to 'show' output lines like "a: 15" which could be useful
for debugging or some such purpose.

However, it seems that I can't put the function definition in a file
and import it because I can't find a way to refer to an object in the
main program file from within a module file. I understand that it's a
good thing to contol which namespaces are referenced by which code but
isn't there sometimes a need for code in a module to access the main
program file's namespace? My example may be a little contrived but
isn't this ability legitimately needed at times?

On Mon, Jun 29, 2009 at 11:22 AM, A.T.Hofkamp wrote:
> Robert Lummis wrote:
>>
>> ... or any pre-processing at all?
>>
>> I'm looking for a way to get boiler plate code into the main program
>> file. Of course I could copy and paste it with an editor but I was
>> hoping for something more pythonic. I know about import but that's not
>> the same.
>
> Python is very good at eliminating boilerplating, so import should be enough
> normally.
>
> Could you give an example of what you want to include that cannot be done
> with import?
>
> Albert
>
>



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


Re: [Tutor] does python have something like "#include" in C?

2009-06-29 Thread Robert Lummis
Thanks very much for all your responses. It's pretty clear now that
what I thought I could somehow do is not "pythonic" and for good
reason.

Kent Johnson says it well: "Module dependencies should be one-way" I
can buy that.

On Mon, Jun 29, 2009 at 2:47 PM, Kent Johnson wrote:
> On Mon, Jun 29, 2009 at 1:23 PM, Robert Lummis wrote:
>> Here's an example that seems not possible in python. I'm probably
>> missing something so please enlighten me. I only tried doing this as
>> an exercise to show myself how name references work. I'm not saying
>> it's needed or that it's good practice.
>>
>> I can write the following as a single file and it works as expected:
>>
>> ===snip===
>> #!/usr/bin/python
>>
>> def show(*args):
>>    print
>>    for arg in args:
>>            print arg + ':',
>>            exec('print ' + arg)
>>
>> a=15
>> b='hello'
>> x=['bob',3]
>>
>> show('a')
>> show('a','b')
>> show('a','b','x')
>> ===snip===
>>
>> The calls to 'show' output lines like "a: 15" which could be useful
>> for debugging or some such purpose.
>>
>> However, it seems that I can't put the function definition in a file
>> and import it because I can't find a way to refer to an object in the
>> main program file from within a module file.
>
> Right. We did recently discuss ways to implement this function:
> http://www.mail-archive.com/tutor@python.org/msg35873.html
>
>> I understand that it's a
>> good thing to contol which namespaces are referenced by which code but
>> isn't there sometimes a need for code in a module to access the main
>> program file's namespace? My example may be a little contrived but
>> isn't this ability legitimately needed at times?
>
> Generally no, that would be a design smell. Module dependencies should
> be one-way; if main needs module foo, then foo should not have to know
> about main.
>
> Kent
>



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


Re: [Tutor] Python Programming exercise

2009-07-01 Thread Robert Berman
1. Pay more attention to what ends an if statement (:) also watch your
indentation. 

2.  Code is better than my commentary. This works the way you want it to
work.

password = "qwerty"
guess = "0"
count = 0
while count != 3:
guess = raw_input("Enter your password: ")
guess = str(guess)
if guess != password:
print "Access Denied"
count = count + 1   
else:
print "Password Confirmed"
break

Robert Berman


On Tue, 2009-06-30 at 19:53 -0700, Daniel Sato wrote:
> I have been going through some Python Programming exercises while
> following the MIT OpenCourseWare Intro to CS syllabus and am having
> some trouble with the first "If" exercise listed on this page:
> 
> http://en.wikibooks.org/wiki/Python_Programming/Conditional_Statements#If_Exercises
> 
> I have been able to make the module quit after entering a password
> three times, but can't get it to quit right away after the correct one
> is entered.  I know this is really basic, please forgive me.  I have
> no programming experience and have just started going through these
> tutorials.
> 
> My code is here:
> 
> http://python.pastebin.com/m6036b52e
> 
> -- 
> Daniel Sato
> http://www.danielsato.com
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

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


Re: [Tutor] When are strings interned?

2009-07-01 Thread Robert Berman


On Wed, 2009-07-01 at 16:44 +0100, Angus Rodgers wrote:
> Hello, world!
> 
> This is my first post to the Tutor list (although I've already
> posted to comp.lang.python a couple of times).
> 
> I'm currently reading Chapter 4 of Wesley Chun's book, "Core 
> Python Programming" (2nd ed.).
> 
> I find this, in Python 2.5.4, on my Win98SE system (using IDLE):
> 
> >>> n = "colourless"
> >>> o = "colourless"
> >>> n == o
> True
> >>> n is o
> True
> >>> p = "green ideas"
> >>> q = "green ideas"
> >>> p == q
> True
> >>> p is q
> False
> 
> Why the difference?

The string p is equal to the string q. The object p is not the object q.

Robert

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


Re: [Tutor] append question

2009-07-05 Thread Robert Berman
In [1]: test=[[1,2,3],[4,5,6],[7,8,9]]
In [3]: testvar2 = []

In [16]: for i in range(len(test)):
   : testvar2.append(test[i][1])
   : 
   : 

In [17]: testvar2
Out[17]: [2, 5, 8]

Robert


On Sun, 2009-07-05 at 15:57 -0700, Steven Buck wrote:
> Hi Python Tutors:
>  
> I have a data structure that looks like:
>  
> >>> test=[[1,2,3],[4,5,6],[7,8,9]]
>  
> I want to define a new variable that captures the second element of
> each sublist from above:
>  
> >>> testvar2 = []
>  
> Next I try to capture the aforementioned elements:
>  
> >>> for i in len(test):
> testvar2.append(test[i][2])
>  
> I want testvar2 = [2,5,8] but instead I get the following error
> message:
>  
> Traceback (most recent call last):
>   File "", line 1, in 
> for i in len(test):
> TypeError: 'int' object is not iterable
>  
> Any insight would be appreciated.
> Thanks
> Steve
>  
>  
>  
>  
>  
> 
>  
> 
> 
> -- 
> Steven Buck
> Ph.D. Student
> Department of Agricultural and Resource Economics
> University of California, Berkeley
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

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


Re: [Tutor] Python Tutorials: How to create useful programs after learning the syntax?

2009-07-06 Thread Robert Berman
I have programmed since I was 21. Since I am now retired; that gives me
a tad of experience in some aspects of coding. I have only been using
Python for two years and I enjoy it for two reasons; the first and most
important is it is fun. if you don't enjoy the language, find another
one you do enjoy. And, finally, it is a language that lends itself to
some really creative solutions. 

I do not know if your interest extends to games, designing user
Graphical input programs, or puzzle solving. I have done two for most of
my professional life; games are not at all my forte. I am impressed with
them (my wife loves them, but I have neither the artistic design skills
or the patience).  I have worked primarily as a consultant to law
enforcement and have designed and implemented juvenile justice systems,
and done work in both drug rehabilitation database studies, and child
support studies as well.

Now, my interest has turned to puzzle solving and I feel this is a
wonderful method to hone your skills. I would suggest, if this at all
piques your interest, you take a look at the following sites. The order
is of no bearing at all. What I find complex you will not, so these
suggestions I simply pulled from my bookmarks and  hope they might give
you both asistance and simple pleasure

1.  http://www.challenge-you.com/
2.  http://projecteuler.net/index.php?section=logout
3.  http://www.spoj.pl/problems/classical/
4.  http://codegolf.com/
5.  http://www.codechef.com/

These will certainly keep you occupied for many hours, days, weeks, etc.

Enjoy,


Robert




On Sun, 2009-07-05 at 23:48 -0700, Luis Galvan wrote:
> Hello all, this is my first time using a mailing list, so I'm not sure
> if I'm doing this right!  Anyway, I have a wee bit of a problem.  I've
> recently completed watching a Youtube video series on Python 2.6 by
> thenewboston which helped me a TON with learning Python's syntax and
> how to use some of the various builtin modules.  I am very thankful
> for his tutorials, but the only thing that I need is something to help
> me really grasp onto the world of programming. (I'm new to
> programming)  What I'm looking for is a tutorial series that walks you
> through the steps of writing a useful program in Python.  Whether it
> be a text editor, a simple browser, etc, it doesn't really matter.  I
> learned the syntax (at least most of it), but I guess I'm just looking
> for something to help me learn to "utilize it".  Something to teach me
> how I can use everything I learned about manipulating strings,
> creating classes, and importing modules and how to stir it all up into
> something meaningful.  Most people's answer to this kind of question
> is that the best way to learn is to "play around with it", but
> personally I believe that you can't really play with it if it you
> don't know where to start.  If anyone has any idea on how I can really
> get started with programming useful programs, please do let me know!
> Any help would be immensely appreciated!  
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

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


  1   2   3   4   >