[Tutor] Bootstrapping PYTHONPATH

2006-09-05 Thread Terrence Brannon
I'm writing a suite of data processing scripts with this layout

Data/Vendor/A/proc.py
Data/Vendor/B/proc.py
Etc, etc

Now, I started down the road of having a global config file in
Data/Vendor/Global.ini and a per-vendor local config file in
Data/Vendor/A/Local.ini

But then I realized that I hate any and all mini-languages. I hate embedded
templating languages for dynamic HTML generation (I prefer DOM). And I now
hate mucking about with configuration systems. I prefer language and library
over shortcut mini-languages in this case as well.

Thus, instead of using a merge() operation between the global and local, I
want to have a base class for configuration to replace Global.ini and I want
to extend it in each vendor. To wit:

 class config:
def ftpserver(): "generalftp.com"
 
In vendor, extending base class

 class config(config):
def ftpserver(): "specificftp.com"

And in my code, I want to have:

 import config # imported from Data/Vendor/A/config.py
   # which extends Data/Vendor/config.py

 c = config()  # merged config

 ftp = FTP(c.ftpserver()) # "specificftp.com"

So my big problem is how to make each local config available to each local
proc.py. I've thought of some approaches:

* alias python to dataproc and make this a shell script with extends
PYTHONPATH before calling proc.py
* use a setup.py in each directory and install them in site-packages
* Some deep magic line that parses __file__ and adds to PYTHONPATH


Any feedback on how to do this is appreciated.



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


Re: [Tutor] Where to post a Python Program

2006-09-05 Thread Collin Hockey
I've posted things to http://www.uselesspython.com before. They don't 
have a specific comment form, but you can allow users to e-mail you with 
responses.

Carroll, Barry wrote:
> Greetings:
> 
>  
> 
> I have written a console version of the dice game Yahtzee).  I would 
> like to post it for comment. It is too long to post here and I don’t 
> have a web site.  Is there some place where I can post my code and get 
> feedback about it?
> 
>  
> 
> Regards,
> 
>  
> 
> Barry
> 
> [EMAIL PROTECTED] 
> 
> 541-302-1107
> 
> /*//*/
> 
> */We who cut mere stones must always be envisioning cathedrals./**//*
> 
> */—Quarry worker's creed/**//*
> 
>  
> 
> 
> 
> 
> ___
> 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] Hi All

2006-09-05 Thread Mike Hansen
 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Amit Rane
> Sent: Saturday, September 02, 2006 4:52 AM
> To: tutor@python.org
> Subject: [Tutor] Hi All
> 
> Hi , 
> This is Amit from India ...
> i have just started working on Python ...
> please let me know the books to refer to start
> learning 
> python ..as of now i am going thru online books ...
> please let me know if any additional books are there .
> 
> 
> 
> Thanks & Regards ,
> Amit Rane
> 
> 

This question gets asked a lot, so here's a tinyurl link to the FAQ on
this topic.

http://tinyurl.com/kl9bu

which is
http://pyfaq.infogami.com/tutor-what-are-some-good-books-on-python
**
IMPORTANT: The contents of this email and any attachments are confidential. 
They are intended for the 
named recipient(s) only.
If you have received this email in error, please notify the system manager or 
the sender immediately and do 
not disclose the contents to anyone or make copies thereof.
*** eSafe scanned this email for viruses, vandals, and malicious content. ***
**

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


Re: [Tutor] Where to post a Python Program

2006-09-05 Thread Daniel McQuay








> Greetings:

> 

> I have written a console version of the dice game
Yahtzee).  I would like to post it for comment. It is too long to post
here and I don’t have a web site.  > Is there some place where I
can post my code and get feedback about it?

 

Hey Barry, 

 

There are several websites that allow you
to post your code for review. I think one of the best ones is [http://pastebin.com/].
You should also have a look at [http://pastebin.ca/] (not sure if they are affiliated)
which happened to turn up during a google search. 

 

HTH,

Daniel McQuay
www.prowiseguys.com
[EMAIL PROTECTED]
814.825.0847 

 






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


[Tutor] Where to post a Python Program

2006-09-05 Thread Carroll, Barry








Greetings:

 

I have written a console version of the dice game Yahtzee). 
I would like to post it for comment. It is too long to post here and I don’t
have a web site.  Is there some place where I can post my code and get
feedback about it?

 

Regards,

 

Barry

[EMAIL PROTECTED]

541-302-1107



We who cut mere stones must always be
envisioning cathedrals.

—Quarry worker's creed

 






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


Re: [Tutor] [tutor] how to cast to stucture

2006-09-05 Thread Kent Johnson
[EMAIL PROTECTED] wrote:
> Hi list,
>
> i have a complex data in binary file and i want to read its
> fields... the C way is to read file in buffer and then cast
> it to proper structure. Is there a way to do the same in
> Python or i have to read the data byte by byte ?

As well as the struct module you might want to look at pyconstruct which 
is a bit higher-level.
http://pyconstruct.wikispaces.com/

Kent

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


Re: [Tutor] about tkinter

2006-09-05 Thread Alan Gauld
> you can use a "hidden" root window, like this:
> 
>root = Tk()
>root.withdraw()# hide the root window

Aha! I thought there should be a better way than defining the 
size to be 1 pixel! :-)

Thanks for that tip Michael,

Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Q

2006-09-05 Thread Alan Gauld

> my Q is how do you learn the languge of python ? 
> and how do you program?

Visit the Python website, download and install Python 
for your platform.

Visit the beginners page and find a beginners tutorial 
that you like (maybe mine).

http://wiki.python.org/moin/BeginnersGuide/NonProgrammers

Read it until you don't understand something, then 
ask a specific question here.

HTH,

Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [tutor] how to cast to stucture

2006-09-05 Thread Alan Gauld
> i have a complex data in binary file and i want to read its
> fields... the C way is to read file in buffer and then cast
> it to proper structure. Is there a way to do the same in
> Python or i have to read the data byte by byte ?

You can use the struct module to unpack an arbitrary 
sequence of bytes. You can find a very basic intro to 
struct in the File Handliung topic of my tutorial.

But its not as simple as in C where you can more 
or less map a memory area onto a structuure, you'll 
need to extract each field and inert it into the 
equivalent Python data structure - but if that is a 
class you can write a method (load say?) to do the 
heavy work and just call load(file) or whatever when 
needed.

Alan G.

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


Re: [Tutor] about tkinter

2006-09-05 Thread Alan Gauld
>> Here is a very short example of creating two windows:
>>
>> >>> from Tkinter import *
>> >>> win = Tk()
>> >>> win1 = Toplevel(win)
>> >>> f = Frame(win)
>> >>> f.pack()
>> >>> g = Frame(win1)
>> >>> g.pack()
>> >>> Label(f,text="Main").pack()
>> >>> Label(g,text="Sub").pack()
>> >>> win.mainloop()

> If I close the 'main' window, 'sub' window will be closed too. How 
> can
> I close just one window?

You need to hide the main window (there must be one(*) but it can be
very small!) and then make all your visible windows Toplevels.

(*)That may not be true but I don't know of a way to avoid it...

Alan g. 

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


Re: [Tutor] Q

2006-09-05 Thread tomd
> my Q is how do you learn the languge of python ? and how do you program?

see http://www.freenetpages.co.uk/hp/alan.gauld/

-- 
Tom, http://www.vscripts.net/
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Q

2006-09-05 Thread Kent Johnson
mike park wrote:
> my Q is how do you learn the languge of python ? and how do you program?

Read one of the tutorials here:
http://wiki.python.org/moin/BeginnersGuide/NonProgrammers

Try things out. Experiment. Ask questions on this list when you get 
stuck or don't understand something.

The book "Python Programming for the absolute beginner" by Michael 
Dawson is good for beginners with no programming background.

Kent

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


Re: [Tutor] about tkinter

2006-09-05 Thread Michael Lange
On Tue, 5 Sep 2006 01:46:02 -0700
"linda.s" <[EMAIL PROTECTED]> wrote:

> >
> If I close the 'main' window, 'sub' window will be closed too. How can
> I close just one window?
> Linda

Hi Linda,

you can use a "hidden" root window, like this:

root = Tk()
root.withdraw()# hide the root window
top1 = Toplevel(root)
top2 = Toplevel(root)

Don't forget to define a method that exits the application when the last 
Toplevel
is being closed, because if you close both Toplevels the root window is still 
there and no
way to close it from the gui.
Here is a primitive to show how this might work:

def close_top1():
global top1
top1.destroy()
top1 = None
if top2 is None:
root.quit()

top1.protocol("WM_DELETE_WINDOW", close_top1)

( and the same for top2 of course)

This makes the close_top1() function be executed when the "X" in the window's 
upper right
corner is clicked.

I hope this helps.

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


Re: [Tutor] about tkinter

2006-09-05 Thread linda.s
On 9/5/06, Alan Gauld <[EMAIL PROTECTED]> wrote:
> Hi Linda,
>
> >> Can you be clearer about what exactly you want to do?
> >>
> > I want to open two windows with one having the blue triangle and the
> > other one having the red triangle (the code is attached). I can not
> > figure out how to use toplevel.
>
> Looking at your code it would help the readasbility if you put some
> of it into functions like
> draw_line(seg,color)
> draw_oval(x,y)
>
> Assuming you did this your code would then look a bit like:
>
> root = Tk()
> can = Canvas(root,)
> can.pack()
> for x,y in points1:
> draw_oval(x,y)
> for seg in segs1:
> draw_line(seg,'blue')
> for x,y in points2:
> draw_oval(x,y)
> for seg in seg2:
> draw_line(seg, 'red')
>
> Now I assume that you want to split the code after the first pair
> of figures and create a second window there?
>
> You can use Toplevel just as you do root:
>
> top = Toplevel(root)
> can2 = Canvas(top,...)
> can2.pack()
>
> Note that because Toplevel inherits from root you only
> need the one mainloop() call, usually placed at the end
> of your code
>
> Here is a very short example of creating two windows:
>
> >>> from Tkinter import *
> >>> win = Tk()
> >>> win1 = Toplevel(win)
> >>> f = Frame(win)
> >>> f.pack()
> >>> g = Frame(win1)
> >>> g.pack()
> >>> Label(f,text="Main").pack()
> >>> Label(g,text="Sub").pack()
> >>> win.mainloop()
>
> BTW I personally find it best not to pack widgets directly
> into the toplevel/root window but to first insert a frame. Then
> pack the other widgets(like your canvas or my Labels) into
> the frame - it seems to make things behave a little
> more predictably.)
>
> HTH,
>
> Alan G.
>
>
If I close the 'main' window, 'sub' window will be closed too. How can
I close just one window?
Linda
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Q

2006-09-05 Thread mike park
my Q is how do you learn the languge of python ? and how do you program?


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


Re: [Tutor] about tkinter

2006-09-05 Thread Alan Gauld
Hi Linda,

>> Can you be clearer about what exactly you want to do?
>>
> I want to open two windows with one having the blue triangle and the
> other one having the red triangle (the code is attached). I can not
> figure out how to use toplevel.

Looking at your code it would help the readasbility if you put some
of it into functions like
draw_line(seg,color)
draw_oval(x,y)

Assuming you did this your code would then look a bit like:

root = Tk()
can = Canvas(root,)
can.pack()
for x,y in points1:
draw_oval(x,y)
for seg in segs1:
draw_line(seg,'blue')
for x,y in points2:
draw_oval(x,y)
for seg in seg2:
draw_line(seg, 'red')

Now I assume that you want to split the code after the first pair
of figures and create a second window there?

You can use Toplevel just as you do root:

top = Toplevel(root)
can2 = Canvas(top,...)
can2.pack()

Note that because Toplevel inherits from root you only
need the one mainloop() call, usually placed at the end
of your code

Here is a very short example of creating two windows:

>>> from Tkinter import *
>>> win = Tk()
>>> win1 = Toplevel(win)
>>> f = Frame(win)
>>> f.pack()
>>> g = Frame(win1)
>>> g.pack()
>>> Label(f,text="Main").pack()
>>> Label(g,text="Sub").pack()
>>> win.mainloop()

BTW I personally find it best not to pack widgets directly
into the toplevel/root window but to first insert a frame. Then
pack the other widgets(like your canvas or my Labels) into
the frame - it seems to make things behave a little
more predictably.)

HTH,

Alan G. 

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


Re: [Tutor] [tutor] how to cast to stucture

2006-09-05 Thread Pawel Kraszewski
Dnia wtorek, 5 września 2006 08:32, [EMAIL PROTECTED] napisał:

> i have a complex data in binary file and i want to read its
> fields... the C way is to read file in buffer and then cast
> it to proper structure. Is there a way to do the same in
> Python or i have to read the data byte by byte ?

cite:

-
struct -- Interpret strings as packed binary data 
 
 
 This module performs conversions between Python values and C structs 
represented as Python strings. It uses format strings (explained below) as 
compact descriptions of the lay-out of the C structs and the intended 
conversion to/from Python values. This can be used in handling binary data 
stored in files or from network connections, among other sources.
-


see http://docs.python.org/lib/module-struct.html

-- 
 Pawel Kraszewski
 http://www.kraszewscy.net
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] about tkinter

2006-09-05 Thread linda.s

On 8/9/06, Alan Gauld <[EMAIL PROTECTED]> wrote:

Linda,

> Is that possible to open two Tkinter from one python shell?

Tkinter is a python module. You can't really open a Tkinter,
you can only import the module. What you can do is write
a Tkinter application with multiple windows.

You can have as many Tkinter applications running as
you like but they will all be separate processes.

Can you be clearer about what exactly you want to do?

Alan G.


I want to open two windows with one having the blue triangle and the
other one having the red triangle (the code is attached). I can not
figure out how to use toplevel.
Linda
from Tkinter import *
root = Tk()
canW=800
canH=600
can = Canvas(root,bg="white",width=canW,height=canH)
can.pack()
points1=((100,100),(300,400),(400,100))
for pp in points1:
   x = pp[0]
   y = pp[1]
   can.create_oval(x-4,y-4,x+4,y+4,fill='red')

segs1=(((100,100),(300,400)),((100,100),(400,100)),((300,400),(400,100)))

for seg in segs1:
   x1 = seg[0][0]
   y1 = seg[0][1]
   x2 = seg[1][0]
   y2 = seg[1][1]
   can.create_line(x1,y1,x2,y2,fill='blue')
#root.mainloop()
points2=((50,400),(400,200),(300,200))
for pp in points2:
   x = pp[0]
   y = pp[1]
   can.create_oval(x-4,y-4,x+4,y+4,fill='blue')

segs2=(((50,400),(400,200)),((50,400),(300,200)),((400,200),(300,200)))

for seg in segs2:
   x1 = seg[0][0]
   y1 = seg[0][1]
   x2 = seg[1][0]
   y2 = seg[1][1]
   can.create_line(x1,y1,x2,y2,fill='red')
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor