Re: [Tutor] Help with pi and the math module.

2005-09-26 Thread paul brian
it might be a little clearer if you look at sys.modules


In the sys module is a useful dictionary called "modules"
This dictionary maps all the names of modules we import, to the objects
that are those modules.

for example (I am only importing pprint to make it easier to read)

>>> import sys, pprint
>>> pprint.pprint( sys.modules )
{'UserDict': ,
 '__builtin__': ,
 '__main__': ,
 'copy_reg': ,
 ...
 'sys': ,
 'types': ,
 'warnings': ,
 'zipimport': }


So how does an import change this "namespace"?

Well, lets try one. I am going to choose the math module, becasue it has an
easy to spot constant in there called pi.

>>> import math
>>> pprint.pprint( sys.modules )
...
 'math': ,
...

aha - that was not there earlier.

>>> import sys, pprint
>>> import math
>>> sys.modules['__main__'].__dict__['pi']
Traceback (most recent call last):
  File "", line 1, in ?
KeyError: 'pi'
>>> sys.modules['__main__'].__dict__['math']

>>> math.pi
3.1415926535897931


So in the namespace of __main__ (where we run the interpreter) there
exists a module named 'math', and this module holds in its namespace a constant
called pi.

Now lets restart our python interepreter and try again

>>> import sys, pprint
>>> from math import *
>>> import sys, pprint
>>> pprint.pprint( sys.modules )
...
 'math': 
...

There it is again. ?

Now if i have a look at the __main__ namespace (its __dict__)

>>> sys.modules['__main__'].__dict__['math']
Traceback (most recent call last):
  File "", line 1, in ?
KeyError: 'math'
>>> sys.modules['__main__'].__dict__['pi']
3.1415926535897931

math is not in the namespace, but pi is directly there.
Thats the difference between

import math which imports a module into the current namespace

and

from math import *
 which imports all the contents of math into the namespace

one last thing

>>> import random as offthewall
>>> pprint.pprint( sys.modules )
...
 'pprint': ,
 'random': ,
...
>>> random.randint(1,10)
Traceback (most recent call last):
  File "", line 1, in ?
NameError: name 'random' is not defined

Whoops - but it is clearly shown in the sys.modules. That is correct - because
we have imported the module (file) called random.  However when I am in
the __main__ namespace and do random.randint(1,10), Python tries to find
"random" in the __main__namespace.

>>> sys.modules['__main__'].__dict__['offthewall']

>>> sys.modules['__main__'].__dict__['random']
Traceback (most recent call last):
  File "", line 1, in ?
KeyError: 'random'


We have imported the module random but with a name of offthewall
so

>>> offthewall.randint(1,10)
1
>>> offthewall.randint(1,10)
8

works fine.



On 9/24/05, Pujo Aji <[EMAIL PROTECTED]> wrote:
> hi,
>
> if you use : import math
> you can type: diameter * math.pi
>
> if you use from math import *
> you can type: diameter * pi
>
> Cheers,
> pujo
>
>
> On 9/24/05, Nathan Pinno <[EMAIL PROTECTED]> wrote:
> >
> >
> > Hi all,
> >
> > I need help with pi and the math module. I had import math at the top of a
> program, but when it came to diameter*pi, it said that pi was not defined.
> >
> > How do I use it correctly?
> >
> > Thanks,
> > Nathan Pinno
> > ___
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
> >
> >
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
>


--
--
Paul Brian
m. 07875 074 534
t. 0208 352 1741
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Problem with BeautifulSoup

2005-09-26 Thread Kent Johnson
Bernard Lebel wrote:
> Hi grouchy,
> 
> I seem to have found the problem. Somehow, it seems BeautifulSoup
> doesn't like nested tags of the same name.

This seems to be a feature of BS. It seems a bit of a misfeature when applied 
to XML but anyway...you can configure BS with a set of tags which can be 
nested, then it will properly parse your data. Here is a short program that 
shows how:

xml = '''

  1

'''

import BeautifulSoup

class NestingParser(BeautifulSoup.BeautifulStoneSoup):
NESTABLE_TAGS = BeautifulSoup.buildTagMap([], 'parameter')

soup = NestingParser(xml)
print soup.prettify()


Kent

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


[Tutor] wxPython problem

2005-09-26 Thread Øyvind
Hello.

I have been reading the
http://wiki.wxpython.org/index.cgi/Getting_20Started manual and are
running the program there. (Enclosed below).

When I run it, it works fine. But, when I run it again, I get the error
PyNoAppError: The wx.App object must be created first! I assume I have
killed the object and have to create it again. But how would I do that?
reload(MainWindow) does not work. Any suggestions?

Thanks in advance.


-
import os
import wx
ID_ABOUT=101
ID_EXIT=110
class MainWindow(wx.Frame):
def __init__(self,parent,id,title):
wx.Frame.__init__(self,parent,wx.ID_ANY, title, size = ( 200,100),

style=wx.DEFAULT_FRAME_STYLE|
wx.NO_FULL_REPAINT_ON_RESIZE)
self.control = wx.TextCtrl(self, 1, style=wx.TE_MULTILINE)
self.CreateStatusBar() # A StatusBar in the bottom of the window
# Setting up the menu.
filemenu= wx.Menu()
filemenu.Append(ID_ABOUT, "&About"," Information about this program")
filemenu.AppendSeparator()
filemenu.Append(ID_EXIT,"E&xit"," Terminate the program")
# Creating the menubar.
menuBar = wx.MenuBar()
menuBar.Append(filemenu,"&File") # Adding the "filemenu" to the
MenuBar
self.SetMenuBar(menuBar)  # Adding the MenuBar to the Frame content.
wx.EVT_MENU(self, ID_ABOUT, self.OnAbout) # attach the menu-event
ID_ABOUT to the
   # method
self.OnAbout
wx.EVT_MENU(self, ID_EXIT, self.OnExit)   # attach the menu-event
ID_EXIT to the
   # method
self.OnExit
self.Show(True)
def OnAbout(self,e):
d= wx.MessageDialog( self, " A sample editor \n"
" in wxPython","About Sample Editor", wx.OK)
# Create a message dialog box
d.ShowModal() # Shows it
d.Destroy() # finally destroy it when finished.
def OnExit(self,e):
self.Close(True)  # Close the frame.
app = wx.PySimpleApp()
frame = MainWindow(None, -1, "Sample editor")
app.MainLoop()

-- 
This email has been scanned for viruses & spam by Decna as - www.decna.no
Denne e-posten er sjekket for virus & spam av Decna as - www.decna.no

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


[Tutor] script question

2005-09-26 Thread Chris Hallman

I needed a script that takes command line arguments, searches an ini
file for a match to the arguments and then executes a Windows
executable. This is my first script using python so I wanted to make
sure I made
the most of the language. I took bits and pieces from different
tutorials and examples online. The script is executed in this manner:


python search_interface.py device interface interface_name "is down - 00:00:00 01/01/06"



Here is the script:


import ConfigParser, string, sys

section = sys.argv[1]

port = sys.argv[3]

INI=ConfigParser.ConfigParser()

INI.read("interfaces.ini")

passwordentries=[p for p in INI.options(section)]

passwordlist=[INI.get(section, pw) for pw in passwordentries]

print passwordlist

for i in passwordlist:

    if i == port:

      
 os.system("d:\\tnd\\bin\\cawto.exe -cat NetNet " + sys.argv[1] +
" " + sys.argv[2] + " " + sys.argv[3] + " " + sys.argv[4])



I'd like to know if there is a more efficient way to do this and if
there is a way to have these functions performed with the least amount
of time possible (the ini file could grow quite large).



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


Re: [Tutor] script question

2005-09-26 Thread Kent Johnson
Chris Hallman wrote:
> The script is executed in this 
> manner:
> 
> python search_interface.py device interface interface_name "is down - 
> 00:00:00 01/01/06"
> 
> Here is the script:
> 
> import ConfigParser, string, sys
> section = sys.argv[1]
> port = sys.argv[3]
> INI=ConfigParser.ConfigParser()

Generally all caps names are used for constants, it would be more idiomatic to 
use ini.

> INI.read("interfaces.ini")
> passwordentries=[p for p in INI.options(section)]

This could just be 
passwordentries = INI.options(section), which is already a list. But even 
better, see below...

> passwordlist=[INI.get(section, pw) for pw in passwordentries]

The above two lines can be replaced with
passwordlist = [value for name, value in INI.items(section)]
which just accesses the section once.

Kent

> print passwordlist
> for i in passwordlist:
> if i == port:
> os.system("d:\\tnd\\bin\\cawto.exe -cat NetNet " + sys.argv[1] + 
> " " + sys.argv[2] + " " + sys.argv[3] + " " + sys.argv[4])
> 
> 
> I'd like to know if there is a more efficient way to do this and if 
> there is a way to have these functions performed with the least amount 
> of time possible (the ini file could grow quite large).
> 
> 
> 
> Thanks!!
> 
> 
> 
> 
> ___
> 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] wxPython problem

2005-09-26 Thread Franz Steinh�usler
On Mon, 26 Sep 2005 13:41:32 +0200 (CEST), Øyvind <[EMAIL PROTECTED]> wrote:

>Hello.
>
>I have been reading the
>http://wiki.wxpython.org/index.cgi/Getting_20Started manual and are
>running the program there. (Enclosed below).
>
>When I run it, it works fine. But, when I run it again, I get the error
>PyNoAppError: The wx.App object must be created first! I assume I have
>killed the object and have to create it again. But how would I do that?
>reload(MainWindow) does not work. Any suggestions?
>
>Thanks in advance.


Hi,

Windows? Linux? wxPyVersion?

This sounds familiar to me, but I can't
remember exactly.

how do you run it?
in command prompt?
from a python shell (Idle, Pycrust)?

--
Franz Steinhaeusler

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


Re: [Tutor] wxPython problem

2005-09-26 Thread Øyvind
Sorry... Forgot all about that.

Using WinXP, ActiveState Python 2.3 and wx-version 2.6.1.0.

I run it in ActiveStates Interactive Window, which is IDLE (I think).

Thanks in advance



http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] script question

2005-09-26 Thread Christopher Arndt
Chris Hallman schrieb:
> for i in passwordlist:
> if i == port:
> os.system("d:\\tnd\\bin\\cawto.exe -cat NetNet " + sys.argv[1] +
> " " + sys.argv[2] + " " + sys.argv[3] + " " + sys.argv[4])

1) The last line can be also expressed as:

os.system(r"d:\tnd\bin\cawto.exe -cat NetNet %s" % (" ".join(sys.argv[1:5]),))

sys.argv is a list of strings (from which we're only using elements 1-4), which
you can concatenate with the join() method of strings. Then use the '%' string
operator to add it to the command string.

If your command line arguments might contain spaces, you should quote them like
this:

os.system(r"d:\tnd\bin\cawto.exe -cat NetNet %s" % (" ".join(['"%s"' % x for x
in sys.argv[1:5]]),))

You'll find more information about these methods and operators in the standard
library docs section 2.3.

2) I also used a raw string (r'') to avoid having to use double backslashes in
windows paths all the time.

3) Assuming that sys.argv[3] (port) will only match one password in
passwordlist, you can also shorten the for/if construction to:

if port in passwordlist:
os.system(...)

because you're not actually using any of the information from the ini file in
your command line.

4) As to your question regarding efficiency of the script, unfortunately the
ConfigParser module parses the whole INI file unconditionally. You could look
for other third-party configuration file parsers that might do this more
efficiently, but I can not help you there. Start looking a the Cheese shop
(www.python.org/pypi)

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


Re: [Tutor] wxPython problem

2005-09-26 Thread Franz Steinh�usler
On Mon, 26 Sep 2005 14:32:53 +0200 (CEST), Øyvind <[EMAIL PROTECTED]> wrote:

>Sorry... Forgot all about that.
>
>Using WinXP, ActiveState Python 2.3 and wx-version 2.6.1.0.
>
>I run it in ActiveStates Interactive Window, which is IDLE (I think).
>
>Thanks in advance
>
>

Aha, I thought something similar.

It is always a problem to run 2 different 
or competing GUI's the same time.

IDLE with wxPython or Active State Python (they
use the win32 extensions)

The best possibility is to use an IDE, which fits
to the GUI.

Pycrust as shell,
Editor and IDE's: DrPython, spe, Boa Constructor,...
or simply use SciTE as editor and with F5, you can
start your typed in Program and on the right you
have an output pane (With DrPython, you have these
possibilities and many more).

--
Franz Steinhaeusler

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


Re: [Tutor] Challenge [was Re: Why won't it enter the quiz?]

2005-09-26 Thread Nathan Pinno



Bob,
 
I did what you 
suggested. Take another look, and tell me if you were a potential customer, 
would you purchase something?
 
Why not take 
the challenge? It's not like I'm asking much.
 
Nathan 
Pinno

  - Original Message - 
  From: 
  bob 

  To: Nathan Pinno 
  Cc: tutor@python.org 
  Sent: Thursday, September 22, 2005 10:08 
  PM
  Subject: Re: [Tutor] Challenge [was Re: 
  Why won't it enter the quiz?]
  At 06:42 PM 9/22/2005, Nathan Pinno wrote:
  The URL is http://zoffee.tripod.com/purchasecomprogs.htm[snip]At 
  your invitation I visited the site. I personally would not purchase anything 
  listed there due to insufficient information. I don't know what I'm 
  getting!I suggest you dedicate a page to each program with at least 
  one screenshot and explanation of what the program does. 

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


Re: [Tutor] Exception handling - syntaxerror?!

2005-09-26 Thread Andrei
Krishna wrote:
> When I have this piece of code in a function, it works fine. So is
> this some limitation of directly working out off the console?

It is indeed valid Python (you don't have to have empty lines after 
try-except in a real Python program).

> Seems the console supports complete code constructs only  I.e., I can
> have one complete try...except block, a if block etc., but not a bunch
> of constructs? Is my assumption correct?

That seems to cover it, one compound statement per >>>. (You can chain 
several statements in one line by using ';', e.g. ">>> print 6; print 5" 
will work just fine.

-- 
Yours,

Andrei

=
Mail address in header catches spam. Real contact info:
''.join([''.join(s) for s in zip(
"[EMAIL PROTECTED] pmfe!Pes ontuei ulcpss  edtels,s hr' one oC.",
"rjc5wndon.Sa-re laed o s npbi ot.Ira h it oteesn edt C")])

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


Re: [Tutor] Challenge [was Re: Why won't it enter the quiz?]

2005-09-26 Thread bob


At 10:34 AM 9/26/2005, Nathan Pinno wrote:
Bob,
 
I did what you suggested. Take
another look, and tell me if you were a potential customer, would you
purchase something?
 I tried
http://zoffee.tripod.com/purchasecomprogs.htm
I got "Sorry but the page ... is not here." 
 
Sorry, but the page or the file that you're looking for is not here.

 
Why not take the challenge? It's not like I'm asking much.
 
Nathan Pinno


- Original Message - 

From: bob 

To: Nathan Pinno 

Cc: tutor@python.org 

Sent: Thursday, September 22, 2005 10:08 PM

Subject: Re: [Tutor] Challenge [was Re: Why won't it enter the quiz?]

At 06:42 PM 9/22/2005, Nathan Pinno wrote:

The URL is http://zoffee.tripod.com/purchasecomprogs.htm

[snip]

At your invitation I visited the site. I personally would not purchase anything listed there due to insufficient information. I don't know what I'm getting!

I suggest you dedicate a page to each program with at least one screenshot and explanation of what the program does. 

___
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] Challenge [was Re: Why won't it enter the quiz?]

2005-09-26 Thread Nathan Pinno



The actual URL is http://zoffee.tripod.com/purchasecompprogs.htm 


  - Original Message - 
  From: 
  bob 

  To: Nathan Pinno 
  Cc: tutor@python.org 
  Sent: Monday, September 26, 2005 11:54 
  AM
  Subject: Re: [Tutor] Challenge [was Re: 
  Why won't it enter the quiz?]
  At 10:34 AM 9/26/2005, Nathan Pinno wrote:
  Bob, I did what you suggested. Take another look, 
and tell me if you were a potential customer, would you purchase 
something? I tried http://zoffee.tripod.com/purchasecompprogs.htm 
  I got "Sorry but the page ... is not here."  Sorry, but the page or 
  the file that you're looking for is not here.
  Why not take the challenge? It's not like I'm 
asking much. Nathan 
Pinno

  - Original Message - 
  From: bob 
  To: Nathan Pinno 
  Cc: tutor@python.org 
  Sent: Thursday, September 22, 2005 10:08 PM
  Subject: Re: [Tutor] Challenge [was Re: Why won't it enter the 
  quiz?]
  At 06:42 PM 9/22/2005, Nathan Pinno wrote:
  
The URL is http://zoffee.tripod.com/purchasecomprogs.htm
  [snip]
  At your invitation I visited the site. I personally would not purchase 
  anything listed there due to insufficient information. I don't know what 
  I'm getting!
  I suggest you dedicate a page to each program with at least one 
  screenshot and explanation of what the program does. 
___Tutor 
maillist  -  Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] printing an acronym (fwd)

2005-09-26 Thread Danny Yoo
Forwarding to tutor

-- Forwarded message --
Date: Mon, 26 Sep 2005 08:32:02 -0500
From: Jason Massey <[EMAIL PROTECTED]>
To: Danny Yoo <[EMAIL PROTECTED]>
Subject: Re: [Tutor] printing an acronym

Something like this:

def acro(a):
... b = a.split()
... c = ""
... for d in b:
... c+=d[0].upper()
... return c

other than the horrible variable naming, it works.

>>> acro('international business machines')
'IBM'

On 9/25/05, Danny Yoo <[EMAIL PROTECTED]> wrote:
>
>
> On Sat, 24 Sep 2005 [EMAIL PROTECTED] wrote:
>
> > How could I get the following to print out an acronym for each phrase
> > entered such as if I entered random access memory it word print out RAM?
>
>
> Hello,
>
> Just out of curiosity, are you already familiar with Python's "lists"?
>
> If so, then you might want to try the slightly easier problem of pulling
> out acronyms out of a list of words.  Extracting an acronym out of a list
> like:
>
> ["International", "Business", "Machines"]
>
> ==> "IBM"
>
> is not too bad, and is one step toward doing the original problem on the
> phrase "International Business Machines".
>
>
> Tutorials like:
>
> http://www.freenetpages.co.uk/hp/alan.gauld/tutseq2.htm
>
> and the other tutorials on:
>
> http://wiki.python.org/moin/BeginnersGuide/NonProgrammers
>
> should talk about lists.  Please feel free to ask questions here!
>
> ___
> 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] printing an acronym (fwd)

2005-09-26 Thread Allen John Schmidt, Jr.




Or a shorter version,
a=lambda n: "".join([x[0].upper() for x in n.split()])

Then it is just:
>>> a('random access memory')
'RAM'





Danny Yoo wrote:

  Forwarding to tutor

-- Forwarded message --
Date: Mon, 26 Sep 2005 08:32:02 -0500
From: Jason Massey <[EMAIL PROTECTED]>
To: Danny Yoo <[EMAIL PROTECTED]>
Subject: Re: [Tutor] printing an acronym

Something like this:

def acro(a):
... 	b = a.split()
... 	c = ""
... 	for d in b:
... 		c+=d[0].upper()
... 	return c

other than the horrible variable naming, it works.

  
  

  
acro('international business machines')

  

  
  'IBM'

On 9/25/05, Danny Yoo <[EMAIL PROTECTED]> wrote:
  



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


Re: [Tutor] help getting acronym to print?

2005-09-26 Thread Danny Yoo

> > How could I get the following program to output UDP from the user
> > entering user datagram protcol or IP if internet protocla was entered?

Wait a second.  This looks exactly like this question from just a day ago:

http://mail.python.org/pipermail/tutor/2005-September/041639.html

The acronym question you are asking are pretty much a classic homework
exercise.  I was really hoping the others on the list would be more
careful about giving help, but the damage is done anyway.

If this is coincidence, it certainly looks bad anyway, since it shows
you're not doing much work in looking for answers.  If you are doing
homework, pleas don't ask the Tutor list to do it for you.  See:

http://www.catb.org/~esr/faqs/smart-questions.html

Thanks.

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


Re: [Tutor] Tutor Digest, Vol 19, Issue 66

2005-09-26 Thread David Holland

--- [EMAIL PROTECTED] wrote:

> Send Tutor mailing list submissions to
>   tutor@python.org
> 
> To subscribe or unsubscribe via the World Wide Web,
> visit
>   http://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body
> 'help' to
>   [EMAIL PROTECTED]
> 
> You can reach the person managing the list at
>   [EMAIL PROTECTED]
> 
> When replying, please edit your Subject line so it
> is more specific
> than "Re: Contents of Tutor digest..."
> 
> 
> Today's Topics:
> 
>1. USB Capture Image WebCAM (Alberto Troiano)
>2. Re: time challange (paul brian)
>3. Re: Python DB (paul brian)
>4. Re: time challange (nephish)
>5. PDF (Jorge Ramirez)
>6. Re: USB Capture Image WebCAM (Danny Yoo)
>7. Re: Python DB (Danny Yoo)
>8. Re: Challenge [was Re: Why won't it enter the
> quiz?]
>   (Nathan Pinno)
> 
> 
>
--
> 
> Message: 1
> Date: Thu, 22 Sep 2005 16:17:07 +
> From: "Alberto Troiano" <[EMAIL PROTECTED]>
> Subject: [Tutor] USB Capture Image WebCAM
> To: tutor@python.org
> Message-ID:
> <[EMAIL PROTECTED]>
> Content-Type: text/plain; charset=iso-8859-1;
> format=flowed
> 
> Hey Tutors
> 
> I want to make a program that looks like Conquer Cam
> 
> For those who doesn't know what is it its a program
> that captures images 
> from your USB WebCAM and saves them to send via FTP.
> 
> Anyway, getting to the point I don't know how to get
> the video from the 
> camara to watch it inside a GUI made in Python.
> 
> Is this possible?
> How?
> 
> One step at the time..First I want to accomplish the
> online viewer of the 
> camera and then talk about capturing the image
> 
> I'm using Python 2.3.4 over Windows XP Professional
> 
> Thanks in advanced
> 
> Alberto
> 
> 
> 
Have you thought about doing this on the light side ?
I know this is a bit late but no one else has
suggested it.  To be honest, if you are doing this for
security, Linux would be better for security
reasons.http://www.zoneminder.com/






___ 
Does your mail provider give you access to messages sent to other POP email 
accounts, like your work account? 
Get Yahoo! Mail http://uk.mail.yahoo.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Challenge [was Re: Why won't it enter the quiz?]

2005-09-26 Thread Adam
Can I have a look at the password program by any chance?
Tutor maillist  -  
Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor

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


Re: [Tutor] script question

2005-09-26 Thread R. Alan Monroe

> for i in passwordlist:
>   if i == port:
> os.system("d:\\tnd\\bin\\cawto.exe -cat NetNet " + sys.argv[1] + " " +
>sys.argv[2] + " " + sys.argv[3] + " " + sys.argv[4])

If you don't have duplicates in your list, a "break" after the
os.system line might help, because once you've found what you're
looking for you can skip the rest.


> I'd like to know if there is a more efficient way to do this and if there is
> a way to have these functions performed with the least amount of time
> possible (the ini file could grow quite large).

If you wanted to get tricky you could do things like sort the list and
do a binary search on it instead of a linear search.

Alan

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


Re: [Tutor] script question

2005-09-26 Thread Kent Johnson
Chris Hallman wrote:
> Here is the script:
> 
> import ConfigParser, string, sys
> section = sys.argv[1]
> port = sys.argv[3]
> INI=ConfigParser.ConfigParser()
> INI.read("interfaces.ini")
> passwordentries=[p for p in INI.options(section)]
> passwordlist=[INI.get(section, pw) for pw in passwordentries]
> print passwordlist
> for i in passwordlist:
> if i == port:
> os.system("d:\\tnd\\bin\\cawto.exe -cat NetNet " + sys.argv[1] + 
> " " + sys.argv[2] + " " + sys.argv[3] + " " + sys.argv[4])
> 
> 
> I'd like to know if there is a more efficient way to do this and if 
> there is a way to have these functions performed with the least amount 
> of time possible (the ini file could grow quite large).

*TEST FIRST* Don't optimize until you know it is too slow and you have a test 
case that you can time to see if your 'optimizations' are making it faster.

That said...
RawConfigParser should be faster than ConfigParser because it doesn't try to 
interpolate into the values.

RawConfigParser is built on Python dicts which are very fast, and the parsing 
is pretty simple so that should be fast too. It does copy sections before 
giving you the items so that could be a performance hit.

Since it appears that all you really need to know is if a particular section 
has a particular value, you might be able to write a simple line-by-line file 
scanner to figure it out. That might be faster than ConfigParser - you don't 
have to build the dicts, and you can stop when you find the section of interest.

BUT, again, try it first! Python is pretty fast for this kind of stuff. How 
many entries do you expect to have? How fast does it have to be?

Kent

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


Re: [Tutor] Challenge [was Re: Why won't it enter the quiz?]

2005-09-26 Thread bob


At 10:56 AM 9/26/2005, Nathan Pinno wrote:
The actual URL is
http://zoffee.tripod.com/purchasecompprogs.htm



I did what you suggested. Take another look, and tell me if you were a potential customer, would you purchase something?

No. For one thing I can (if I didn't already have one) buy a "real" calculator for $1.00. Also my WIndows op sys comes with a calculator with much more capabilities.
Also, seeing your screenshots leads me to suspect that the programs are character mode rather than providing a GUI.  This would be a turn off to most computer users.
One marketing clue - tell me how the program will benefit me. All I see is that it will take more work to do a calculation than using a "real" calculator. I think there is no benefit.
I say these things not to discourage you but to encourage you to find ways to give customers something they need/want and can't get some other way or as nice or as cheap or as fun or  IOW if I'm to spend $10 I want some real benefit.
Think about why McDonald's is successful. Why people will spend $ for food that is not outstandingly good. 
How do you find an equivalent benefit for software users?


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


Re: [Tutor] script question

2005-09-26 Thread Kent Johnson
Kent Johnson wrote:
> *TEST FIRST* Don't optimize until you know it is too slow and you
> have a test case that you can time to see if your 'optimizations' are
> making it faster.

Pardon my shouting :-)

Kent

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


Re: [Tutor] Tutor Digest, Vol 19, Issue 82

2005-09-26 Thread sanjay sinha
e interface_name "is down -00:00:00 01/01/06"Here is the script:import ConfigParser, string, syssection = sys.argv[1]port = sys.argv[3]INI=ConfigParser.ConfigParser()INI.read("interfaces.ini")passwordentries=[p for p in INI.options(section)]passwordlist=[INI.get(section, pw) for pw in passwordentries]print passwordlistfor i in passwordlist:if i ==
 port:os.system("d:\\tnd\\bin\\cawto.exe -cat NetNet " + sys.argv[1] + " " +sys.argv[2] + " " + sys.argv[3] + " " + sys.argv[4])I'd like to know if there is a more efficient way to do this and if there isa way to have these functions performed with the least amount of timepossible (the ini file could grow quite large).Thanks!!-- next part --An HTML attachment was scrubbed...URL: http://mail.python.org/pipermail/tutor/attachments/20050926/42fb29b6/attachment-0001.htm--Message: 4Date: Mon, 26 Sep 2005 08:13:38 -0400From: Kent Johnson <[EMAIL PROTECTED]>Subject: Re: [Tutor] script questionCc: tutor@python.orgMessage-ID: <[EMAIL PROTECTED]>Content-Type: text/plain; charset=ISO-8859-1; format=flowedChris Hallman wrote:> The script is executed in this > manner:> > python search_interface.py!
  device
 interface interface_name "is down - > 00:00:00 01/01/06"> > Here is the script:> > import ConfigParser, string, sys> section = sys.argv[1]> port = sys.argv[3]> INI=ConfigParser.ConfigParser()Generally all caps names are used for constants, it would be more idiomatic to use ini.> INI.read("interfaces.ini")> passwordentries=[p for p in INI.options(section)]This could just be passwordentries = INI.options(section), which is already a list. But even better, see below...> passwordlist=[INI.get(section, pw) for pw in passwordentries]The above two lines can be replaced withpasswordlist = [value for name, value in INI.items(section)]which just accesses the section once.Kent> print passwordlist> for i in passwordlist:> if i == port:> os.system("d:\\tnd\\bin\\cawto.exe -cat NetNet " + sys.argv[1] + > " " + sys.argv[2] !
 + " " +
 sys.argv[3] + " " + sys.argv[4])> > > I'd like to know if there is a more efficient way to do this and if > there is a way to have these functions performed with the least amount > of time possible (the ini file could grow quite large).> > > > Thanks!!> > > > > ___> Tutor maillist - Tutor@python.org> http://mail.python.org/mailman/listinfo/tutor--Message: 5Date: Mon, 26 Sep 2005 14:04:39 +0200From: Franz Steinhäusler <[EMAIL PROTECTED]>Subject: Re: [Tutor] wxPython problemTo: tutor@python.orgMessage-ID: <[EMAIL PROTECTED]>Content-Type: text/plain; charset=ISO-8859-1On Mon, 26 Sep 2005 13:41:32 +0200 (CEST), ?yvind
 <[EMAIL PROTECTED]>wrote:>Hello.>>I have been reading the>http://wiki.wxpython.org/index.cgi/Getting_20Started manual and are>running the program there. (Enclosed below).>>When I run it, it works fine. But, when I run it again, I get the error>PyNoAppError: The wx.App object must be created first! I assume I have>killed the object and have to create it again. But how would I do that?>reload(MainWindow) does not work. Any suggestions?>>Thanks in advance.Hi,Windows? Linux? wxPyVersion?This sounds familiar to me, but I can'tremember exactly.how do you run it?in command prompt?from a python shell (Idle, Pycrust)?--Franz Steinhaeusler--Message: 6Date: Mon, 26 Sep 2005 14:32:53 +0200 (CEST)From: ?yvind <[EMAIL PROTECTED]>Subject: Re: [Tutor] wxPython problem!
 To:
 tutor@python.orgMessage-ID: <[EMAIL PROTECTED]>Content-Type: text/plain;charset=iso-8859-1Sorry... Forgot all about that.Using WinXP, ActiveState Python 2.3 and wx-version 2.6.1.0.I run it in ActiveStates Interactive Window, which is IDLE (I think).Thanks in advance< This email has been scanned for viruses & spam by Decna as - www.decna.noDenne e-posten er sjekket for virus & spam av Decna as - www.decna.no--Message: 7Date: Mon, 26 Sep 2005 13:56:25 +0100From: Christopher Arndt <[EMAIL PROTECTED]>Subject: Re: [Tutor] script questionTo:
 Tutor@python.orgMessage-ID: <[EMAIL PROTECTED]>Content-Type: text/plain; charset=ISO-8859-1Chris Hallman schrieb:> for i in passwordlist:> if i == port:> os.system("d:\\tnd\\bin\\cawto.exe -cat NetNet " + sys.argv[1] +> " " + sys.argv[2] + " " + sys.argv[3] + " " + sys.argv[4])1) The last line can be also expressed as:os.system(r"d:\tnd\bin\cawto.exe -cat NetNet %s" % (" ".join(sys.argv[1:5]),))sys.argv

Re: [Tutor] Tutor Digest, Vol 19, Issue 82

2005-09-26 Thread sanjay sinha
e interface_name "is down -00:00:00 01/01/06"Here is the script:import ConfigParser, string, syssection = sys.argv[1]port = sys.argv[3]INI=ConfigParser.ConfigParser()INI.read("interfaces.ini")passwordentries=[p for p in INI.options(section)]passwordlist=[INI.get(section, pw) for pw in passwordentries]print passwordlistfor i in passwordlist:if i ==
 port:os.system("d:\\tnd\\bin\\cawto.exe -cat NetNet " + sys.argv[1] + " " +sys.argv[2] + " " + sys.argv[3] + " " + sys.argv[4])I'd like to know if there is a more efficient way to do this and if there isa way to have these functions performed with the least amount of timepossible (the ini file could grow quite large).Thanks!!-- next part --An HTML attachment was scrubbed...URL: http://mail.python.org/pipermail/tutor/attachments/20050926/42fb29b6/attachment-0001.htm--Message: 4Date: Mon, 26 Sep 2005 08:13:38 -0400From: Kent Johnson <[EMAIL PROTECTED]>Subject: Re: [Tutor] script questionCc: tutor@python.orgMessage-ID: <[EMAIL PROTECTED]>Content-Type: text/plain; charset=ISO-8859-1; format=flowedChris Hallman wrote:> The script is executed in this > manner:> > python search_interface.py!
  device
 interface interface_name "is down - > 00:00:00 01/01/06"> > Here is the script:> > import ConfigParser, string, sys> section = sys.argv[1]> port = sys.argv[3]> INI=ConfigParser.ConfigParser()Generally all caps names are used for constants, it would be more idiomatic to use ini.> INI.read("interfaces.ini")> passwordentries=[p for p in INI.options(section)]This could just be passwordentries = INI.options(section), which is already a list. But even better, see below...> passwordlist=[INI.get(section, pw) for pw in passwordentries]The above two lines can be replaced withpasswordlist = [value for name, value in INI.items(section)]which just accesses the section once.Kent> print passwordlist> for i in passwordlist:> if i == port:> os.system("d:\\tnd\\bin\\cawto.exe -cat NetNet " + sys.argv[1] + > " " + sys.argv[2] !
 + " " +
 sys.argv[3] + " " + sys.argv[4])> > > I'd like to know if there is a more efficient way to do this and if > there is a way to have these functions performed with the least amount > of time possible (the ini file could grow quite large).> > > > Thanks!!> > > > > ___> Tutor maillist - Tutor@python.org> http://mail.python.org/mailman/listinfo/tutor--Message: 5Date: Mon, 26 Sep 2005 14:04:39 +0200From: Franz Steinhäusler <[EMAIL PROTECTED]>Subject: Re: [Tutor] wxPython problemTo: tutor@python.orgMessage-ID: <[EMAIL PROTECTED]>Content-Type: text/plain; charset=ISO-8859-1On Mon, 26 Sep 2005 13:41:32 +0200 (CEST), ?yvind
 <[EMAIL PROTECTED]>wrote:>Hello.>>I have been reading the>http://wiki.wxpython.org/index.cgi/Getting_20Started manual and are>running the program there. (Enclosed below).>>When I run it, it works fine. But, when I run it again, I get the error>PyNoAppError: The wx.App object must be created first! I assume I have>killed the object and have to create it again. But how would I do that?>reload(MainWindow) does not work. Any suggestions?>>Thanks in advance.Hi,Windows? Linux? wxPyVersion?This sounds familiar to me, but I can'tremember exactly.how do you run it?in command prompt?from a python shell (Idle, Pycrust)?--Franz Steinhaeusler--Message: 6Date: Mon, 26 Sep 2005 14:32:53 +0200 (CEST)From: ?yvind <[EMAIL PROTECTED]>Subject: Re: [Tutor] wxPython problem!
 To:
 tutor@python.orgMessage-ID: <[EMAIL PROTECTED]>Content-Type: text/plain;charset=iso-8859-1Sorry... Forgot all about that.Using WinXP, ActiveState Python 2.3 and wx-version 2.6.1.0.I run it in ActiveStates Interactive Window, which is IDLE (I think).Thanks in advance< This email has been scanned for viruses & spam by Decna as - www.decna.noDenne e-posten er sjekket for virus & spam av Decna as - www.decna.no--Message: 7Date: Mon, 26 Sep 2005 13:56:25 +0100From: Christopher Arndt <[EMAIL PROTECTED]>Subject: Re: [Tutor] script questionTo:
 Tutor@python.orgMessage-ID: <[EMAIL PROTECTED]>Content-Type: text/plain; charset=ISO-8859-1Chris Hallman schrieb:> for i in passwordlist:> if i == port:> os.system("d:\\tnd\\bin\\cawto.exe -cat NetNet " + sys.argv[1] +> " " + sys.argv[2] + " " + sys.argv[3] + " " + sys.argv[4])1) The last line can be also expressed as:os.system(r"d:\tnd\bin\cawto.exe -cat NetNet %s" % (" ".join(sys.argv[1:5]),))sys.argv

[Tutor] encode question!

2005-09-26 Thread 铁石
I am trying to write a stript that extract jpg files
 from a html I had downloaded.I encounter a problem with
 a Big5 charset html file.Big5 used in Hongkong ans Taiwan.
In this html file there's a jpg names "xvg_h%202.jpg"
in vi ,the tag of the image is ___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] 2 questions......novice but not beginner

2005-09-26 Thread Mike Pippin
Please HELP...
 
First
I need to know how to allow the user to search their local drives and directories in order to load a file...or if there are any pre-written opensource functions that will also be well appreciated..
Second
I need to know how to render graphics without the windowed enviroment.I know with pygame you can have a windowless enviroment but I need to be able to have only the graphics i choose displayed on the screen without pygame filling the rest of the screen with black if thats possible.

 
ANY HELP WOULD BE GREATLY APPRECIATED.thank you in advance to anyone who can help me!!
 
Mike
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] encode question!

2005-09-26 Thread Danny Yoo


On Tue, 27 Sep 2005, [GB2312] ��ʯ wrote:

> I am trying to write a stript that extract jpg files
>  from a html I had downloaded.I encounter a problem with
>  a Big5 charset html file.Big5 used in Hongkong ans Taiwan.
> In this html file there's a jpg names "xvg_h%202.jpg" in vi ,the tag
> of the image is  image,python report that file "xvg_h%2525202.jpg" don't exists.

It'll help if you show us your program so far, and point us to an example
file in big5 format.

I do not suspect that an encoding issue's in play here; the file name you
are showing us looks regular enough that there may be some other issue.
There are any number of reasons why programs don't work: I'd rather remove
the ambgiuity by seeing real code.

Let's me check something quickly...

##
>>> import codecs
>>> from StringIO import StringIO
>>> sampleText = "xvg_h%202.jpg"
>>> sampleFile = StringIO(sampleText)
>>> translatedFile = codecs.EncodedFile(sampleFile, "big5")
>>> translatedFile.readline()
'xvg_h%202.jpg'
##

As far as I can tell, the filename that you're showing us, 'xvg_h%202.jpg'
doesn't have characters that trigger an alternative interpretation in
big5.  I'm unfamiliar enought with big5, though, that I could be mistaken.
Please point us to a sample text file with big5, and we can do more
realistic tests on this end.


Let me try another experiment with a big5-encoded file and a third-party
html parser called 'BeautifulSoup':

##
>>> import BeautifulSoup
>>> f = urllib.urlopen('http://chinese.yahoo.com')
>>> soup = BeautifulSoup.BeautifulSoup(f)
>>> images = soup('img')
>>> for img in images:
... print img['src']
...
http://us.i1.yimg.com/us.yimg.com/i/b5/home/m6v1.gif
http://hk.yimg.com/i/search/mglass.gif
http://us.i1.yimg.com/us.yimg.com/i/hk/new2.gif
http://hk.yimg.com/i/icon/16/3.gif
http://us.i1.yimg.com/us.yimg.com/i/hk/spc.gif
http://hk.yimg.com/i/home/tabbt.gif
http://hk.yimg.com/i/home/tabp.gif
http://hk.yimg.com/i/home/tabp.gif
http://hk.yimg.com/i/home/tabp.gif
##

That looks sorta ok, although I know I'm completely ignoring big5 issues.
*grin*


Give us a file to work on, and we'll see what we can do to help you parse
it.  Good luck!

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