Re: [Tutor] Feedback on coding style

2010-12-09 Thread Albert-Jan Roskam
Hi,

Re: coding style, I can *really* recommend the book 'Code Complete' 
(http://cc2e.com/). It doesn't focus on Python specifically, but it's a 
wonderful book. You can find a pdf checklist of the book if you Google a bit.
 Cheers!!
Albert-Jan 


~~
All right, but apart from the sanitation, the medicine, education, wine, public 
order, irrigation, roads, a fresh water system, and public health, what have 
the 
Romans ever done for us?
~~ 





From: Dave Angel 
To: howit...@archlinux.us
Cc: tutor@python.org
Sent: Wed, December 8, 2010 11:01:05 PM
Subject: Re: [Tutor] Feedback on coding style

On 01/-10/-28163 02:59 PM, howit...@archlinux.us wrote:
> Hi.
> 
> For the past week, I've been following an online Python guide named:
> 'Learn Python the Hard Way'. I'm very happy with it as it gives a lot of
> freedom to explore.
> 
> However, due to this I have no idea if I'm thinking the right way. That's
> why I've attached a script of mine I've been working on all day.
> 
> It works a 100%, but I'm afraid I've made very bad choices concerning
> design and coding style. (If it could've been much simpler, if there are
> glaring mistakes, poor methods, ..)
> 
> Could anyone be so friendly as to offer a bit of feedback, to a newbie?
> 
> PS: The script very simple accepts 2 arguments from the commandline.
>     First arg being the number to which should be counted,
>     second arg being the interval.
> 
> Thank you,
> Adrian

I agree with Hugo, probably on all his points.  But to help you fix it, I think 
I can help you a bit as well.

First is I think you're misunderstanding the purpose of a function.  A function 
should be a self-contained piece of code that gets called, and that returns 
when 
done.  You're using them mostly as a way to implement what BASIC used to have 
as 
a GOTO.  For example, when a loop is needed, you do it by calling another 
function which calls the first one.  That is called recursion if it's done on 
purpose, and a bug if it happens by accident.

Second is that you're misusing global variables.  A function needs to be called 
with those values it needs to do its work, and it needs to return the results 
of 
that work.  Very seldom should those things be globals.

Start with the first function.  You declare it with maxn and incr as 
parameters, 
and you call it correctly.  But it also uses the globals, rather than using the 
ones passed in.

Then the function ask_change().  You should be passing it the two arguments, 
and 
getting back modified arguments as return values.  And the function shouldn't 
call the_loop() itself, it should just get the new values.

jibjab_result() is trying to be a loop, by effectively calling itself, through 
choice_result().  If you need a loop, just write one.  And that loop will 
probably be in ask_change(), without needing any other functions inside.

It's good to decompose a problem into functions, but you're not using functions 
in the way they're designed.  For small problems, this can work, but as the 
problems get more complex, you'll be forced to change your habits.

DaveA



___
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] role playing game - help needed

2010-12-09 Thread ALAN GAULD
Can you explain this in a little more detail?
>
>
sure.

 
>
>for name in attributes.keys():
>  attributes[name] = int( input("How many points do you want to assign to %s " 
> % 
>name) )
> 
>Where did you get 'name' from?  
>

I made it up. The for loop takes the form

for  in :
  

where the bits in <> are provided by the programmer.
name was just a "meaningful" variable name that I chose.

> What does the % do and how does it work inside the 
> quotation marks as opposed to outside?  

This is called string formatting. Actually in Python 3 there is a new way of 
doing this but the older style, like this, still works.

Basically within the string we insert percent signs followed by 
a special letter to indicate the type of data we want to insert into 
the string. %s means a string, %d a decimal number, %f a floating 
point number etc.

The % immediately after the string is a separator preceding the 
values to be inserted into the string

Try it at the >>> prompt:

>>> "%d is a number" % 6
6 is a number
>>> "%d is the result of %d + %d" % (6+7,6,7)
13 is the result of 6 + 7
>>> "My name is %s" % "Alan"
My name is Alan

Someone else might show you the v3 way using the 
new string.format() operator


HTH,

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


Re: [Tutor] Feedback on coding style

2010-12-09 Thread Alan Gauld

"Albert-Jan Roskam"  wrote


Re: coding style, I can *really* recommend the book 'Code Complete'
(http://cc2e.com/). It doesn't focus on Python specifically, but 
it's a

wonderful book.


I'll second that. I haven't read the 2nd Ed but the first edition was 
one
of the few (5 or 6?) books I've read about computing that actually 
changed

the way I write code.

It's not an absolute beginners book, you need a bit of experience in 
writing
reasonable length programs - more than 100 lines say, to really 
appreciate

why some things are recommended, but for the right audience it is,
as Albert says, a wonderful book..

--
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


Re: [Tutor] Feedback on coding style

2010-12-09 Thread howit...@archlinux.us
Thanks a lot for the very friendly and constructive comments.

I can't wait to start overhauling the script with the
comments received here.

If I could repay the friendliness to anyone, let me know.
Adrian
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Save file in a specific directory

2010-12-09 Thread Susana Iraiis Delgado Rodriguez
Thank you Jerry! The suggestion you told me make my code worked!

>
>
>
> dbf = Dbf(d,new=False, readOnly=True)
>
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] updating databases with null values

2010-12-09 Thread Rance Hall
I have a set of questions that ask about a customers name, address, email, etc.

some of these values are allowed to be null, and others aren't.  Some
are required to have specific formats when they aren't null.

I'm happy with the code Ive written and its question asking routine,
but I need help understanding how best to deal with null values.

I'm connecting to a postgres database with the python postgres module
described here: http://python.projects.postgresql.org/

I'm also using python 3.x if it matters.

The sql is different if you want to allow null values

update table set value = "string" where condition

with null value:

update table set value = NULL where condition

It would seem I need several iterations of the prepared db statement
for various combinations of null values or I don't allow null values
at all and put empty strings in the database instead of the null
value.

Could someone help me think through this idea and help me decide on a
good method.  Right now I'm thinking that I should skip null values
and just store zero length strings in the db.  I don't like it, but
its certainly much easier (at least to me so far)

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


Re: [Tutor] updating databases with null values

2010-12-09 Thread bob gailer

On 12/9/2010 11:46 AM, Rance Hall wrote:

I have a set of questions that ask about a customers name, address, email, etc.

some of these values are allowed to be null, and others aren't.  Some
are required to have specific formats when they aren't null.

I'm happy with the code Ive written and its question asking routine,
but I need help understanding how best to deal with null values.

I'm connecting to a postgres database with the python postgres module
described here: http://python.projects.postgresql.org/

I'm also using python 3.x if it matters.

The sql is different if you want to allow null values

update table set value = "string" where condition

with null value:

update table set value = NULL where condition

It would seem I need several iterations of the prepared db statement
for various combinations of null values or I don't allow null values
at all and put empty strings in the database instead of the null


Offhand I'd say you could use a parameterized stattement, like

update table set value = ? where condition

Then pass either the string or NULL when executing. I don't know 
postgresql's exact way to do this.



value.

Could someone help me think through this idea and help me decide on a
good method.  Right now I'm thinking that I should skip null values
and just store zero length strings in the db.  I don't like it, but
its certainly much easier (at least to me so far)

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




--
Bob Gailer
919-636-4239
Chapel Hill NC

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


[Tutor] Calling Program within Program

2010-12-09 Thread patty

Hello:

I would like to know how to call a program from within a program and what
directory I should place one small program file in.  I am running Python
2.6.6 and Windows 7.

I have a directory called  C:\Users\StarShip\PyProgs and it has the files
BreakersCafe.txt and BreakersCafe.py.  This is my primary program running
fine.

I have a subdirectory called C:\Users\StarShip\PyProg \PicturesForTesting
and another subdirectory C:\Users\StarShip\PyProgs\CustomFunctions with
various program files, functions defined  in them, etc.  which I import in
my primary program.   For example:

 def Newbanner():
print "\n   Alternate Selections\n"

Now I have the small program below which is fully self-contained and I
want to execute it from within  BreakersCafe.txt. I would like to use
raw_input and if statement for simple yes/no asking if they would like to
see this BeveragesMenu.txt and have it as the last 3-4 lines of the
main().

The only directory of these three that has __init__ is
   C:\Users\StarShip\PyProgs\CustomFunctions
and as you can see, the program below is not a function, it has no 'def'
anything.  I get 'NameError: global name 'BeveragesMenu' is not defined'
when I run this in IDLE.  I suppose I _could_ make this a function :} but
it is likely doable to call a program as a program, right?  I am also
compiling to a .pyw file where applicable.

Thanks for the help.

Patty

"""
This is C:\Users\StarShip\PyProgs\BeveragesMenu.txt and BeveragesMenu.py. 
Program file for displaying an image using Tkinter built-in GUI functions.
 open root window, open file descriptor for image, open new window file
descriptor to manipulate with Tkinter Label library function.

Pic needs to be displayed as a banner. Uses the compound="top" argument to
do this.

-->  take out the pack()function didn't work, pack()is required

Uses   import Tkinter

Program using new breaker's jpg picture; bar choices are not selectable
"""


import Tkinter
import ImageTk

rootwindow = Tkinter.Tk()

fhdl=
ImageTk.Image.open("C:\Users\StarShip\PyProgs\PicturesForTesting\houseimage.jpg")
image_var = ImageTk.PhotoImage(fhdl)

whdl = Tkinter.Label(rootwindow, compound="top", image=image_var,
text="\n\n!!!WELCOME TO BREAKER'S BREAKFAST BAR!!!\n\n\nBeverage Choices: 
Sparkling Water;  Milk;  Orange Juice;  Apple Juice  *OR*\n\n  **From Our
Bar**Smoothie;  Breakers Sun Tea;  Chai;  Cafe Mocha;  Latte; 
Mimosa")

whdl.pack()
rootwindow.mainloop()

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


[Tutor] Increment by string, Array

2010-12-09 Thread lmhosie

Hello,
I have a large code that I am using for ARC GIS I know could be much smaller 
but it works like it is. I have programmed in C++ but am just beginning with 
python I believe the answer would be to do a parallel array however I am having 
trouble keeping the SQL statment in the string format it should be and putting 
in the array. So I ended up using a string.template and just incrementing 
manually.
Here is a sample of the code:
 
# ---
# MakeFeature.py
# Created on: Tue Nov 23 2010 11:07:25 AM
#   
# ---
# Import system modules
import sys, string, os, arcgisscripting
# Create the Geoprocessor object
gp = arcgisscripting.create()
gp.overwriteoutput = 1
# Check out any necessary licenses
gp.CheckOutExtension("spatial")
# Load required toolboxes...
gp.AddToolbox("C:/Program Files (x86)/ArcGIS/ArcToolbox/Toolboxes/Spatial 
Analyst Tools.tbx")
gp.AddToolbox("C:/Program Files (x86)/ArcGIS/ArcToolbox/Toolboxes/Data 
Management Tools.tbx")

# Local variables...
wrs_season_Layer = "wrs_season_Layer"
wrs_season_shp = "D:\\model\\wrs_season.shp"
Temp_mdb = "D:\\model\\Temp.mdb"
ecoregions = "D:\\model\\Eco\\wwfecoregions\ecoregions.shp"

t=string.Template("D:\\model\\Temp.mdb\\T$Num")
p = string.Template('"PATH" = $Path')t
 
# Process: 
 
print "Calculating row 1"
gp.MakeFeatureLayer_management(wrs_season_shp, wrs_season_Layer, 
p.substitute(Path ='1'), Temp_mdb,)
gp.TabulateArea_sa(wrs_season_Layer,"PR", ecoregions, "BIOME", t.substitute(Num 
= '1'), "0.01")

print "Calculating row 2"
gp.MakeFeatureLayer_management(wrs_season_shp, wrs_season_Layer, 
p.substitute(Path ='2'), Temp_mdb,)
gp.TabulateArea_sa(wrs_season_Layer,"PR", ecoregions, "BIOME", t.substitute(Num 
= '2'),  "0.01")
print "finished
 
 
#This process repeats for 200 paths each requiring a calculation and a separate 
table creation indicating which path they are calculating#
The problem I had when making $Path a variable is it won't process the SQL 
statement any longer because of the quotes around it. The format has to stay in 
(' "PATH" = X')
for it to ingest correctly, another way would be "\"PATH\" = 1" however the 
same problem arises when you try to turn the 1 into a variable.
 
Any help would be much appreciated I would think I could just create a parallel 
array incrementing by 1 and just looping through for 233 paths?
Thankyou,
Lynn  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Increment by string, Array

2010-12-09 Thread Joel Goldstick
Can you use something like this:

for i in range(1,201):
s = str(i)

Then Path = '1' can become Path = s


On Thu, Dec 9, 2010 at 2:39 PM,  wrote:

>  Hello,
> I have a large code that I am using for ARC GIS I know could be much
> smaller but it works like it is. I have programmed in C++ but am just
> beginning with python I believe the answer would be to do a parallel array
> however I am having trouble keeping the SQL statment in the string format it
> should be and putting in the array. So I ended up using a string.template
> and just incrementing manually.
> Here is a sample of the code:
>
> #
> ---
> # MakeFeature.py
> # Created on: Tue Nov 23 2010 11:07:25 AM
> #
> #
> ---
> # Import system modules
> import sys, string, os, arcgisscripting
> # Create the Geoprocessor object
> gp = arcgisscripting.create()
> gp.overwriteoutput = 1
> # Check out any necessary licenses
> gp.CheckOutExtension("spatial")
> # Load required toolboxes...
> gp.AddToolbox("C:/Program Files (x86)/ArcGIS/ArcToolbox/Toolboxes/Spatial
> Analyst Tools.tbx")
> gp.AddToolbox("C:/Program Files (x86)/ArcGIS/ArcToolbox/Toolboxes/Data
> Management Tools.tbx")
>
> # Local variables...
> wrs_season_Layer = "wrs_season_Layer"
> wrs_season_shp = "D:\\model\\wrs_season.shp"
> Temp_mdb = "D:\\model\\Temp.mdb"
> ecoregions = "D:\\model\\Eco\\wwfecoregions\ecoregions.shp"
>
> t=string.Template("D:\\model\\Temp.mdb\\T$Num")
> p = string.Template('"PATH" = $Path')t
>
> # Process:
>
> print "Calculating row 1"
> gp.MakeFeatureLayer_management(wrs_season_shp, wrs_season_Layer,
> p.substitute(Path ='1'), Temp_mdb,)
> gp.TabulateArea_sa(wrs_season_Layer,"PR", ecoregions, "BIOME",
> t.substitute(Num = '1'), "0.01")
>
> print "Calculating row 2"
> gp.MakeFeatureLayer_management(wrs_season_shp, wrs_season_Layer,
> p.substitute(Path ='2'), Temp_mdb,)
> gp.TabulateArea_sa(wrs_season_Layer,"PR", ecoregions, "BIOME",
> t.substitute(Num = '2'),  "0.01")
> print "finished
>
>
> #This process repeats for 200 paths each requiring a calculation and a
> separate table creation indicating which path they are calculating#
> The problem I had when making $Path a variable is it won't process the SQL
> statement any longer because of the quotes around it. The format has to stay
> in (' "PATH" = X')
> for it to ingest correctly, another way would be "\"PATH\" = 1" however the
> same problem arises when you try to turn the 1 into a variable.
>
> Any help would be much appreciated I would think I could just create a
> parallel array incrementing by 1 and just looping through for 233 paths?
> Thankyou,
> Lynn
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>


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


[Tutor] 'or' in assignment (not if statement)?

2010-12-09 Thread Alex Hall
Hi all,
I am reading the source of a project I hope to help with
(http://www.qwitter-client.net). I sometimes see something like:
val=val or 1
I am guessing that val is an int. If val==0, the 'or' kicks in and
val=1, else the or is not needed and val=val. Am I close? Can other
words or symbols be used in contexts where one would not normally
think of them?
Thanks.

-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] 'or' in assignment (not if statement)?

2010-12-09 Thread Adam Bark

On 10/12/10 00:51, Alex Hall wrote:

Hi all,
I am reading the source of a project I hope to help with
(http://www.qwitter-client.net). I sometimes see something like:
val=val or 1
I am guessing that val is an int. If val==0, the 'or' kicks in and
val=1, else the or is not needed and val=val. Am I close? Can other
words or symbols be used in contexts where one would not normally
think of them?
Thanks.

   

Hi Alex,

This is one of those times the interactive interpreter comes in handy eg:

In [1]: val=5

In [2]: val=val or 1

In [3]: val
Out[3]: 5

In [4]: val=0

In [5]: val=val or 1

In [6]: val
Out[6]: 1

You are right by the way and I know you can't test every possibility 
but, as you already suspected the outcome, this just reinforces it I think.


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


Re: [Tutor] 'or' in assignment (not if statement)?

2010-12-09 Thread Alan Gauld


"Alex Hall"  wrote 


val=val or 1



I am guessing that val is an int. If val==0, the 'or' kicks in and
val=1, else the or is not needed and val=val. Am I close? 


Yes this is a combination of what is known as short circuit 
evaluation of boolean expressions and a quirk of Python that 
returns the actual value of something that is being treated as 
a boolean.


There is a section on this in the Functional Programming 
topic in my tutor which explains and illustrates in much 
more detail.


This particular trick is now deprecated in favour of the new 
conditional expressiion, so your code would now be written as:


val = val if val else 1

Can other words or symbols be used in contexts where one 
would not normally think of them?


See my tutor, it shows how and can be used in similar ways...

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


Re: [Tutor] 'or' in assignment (not if statement)?

2010-12-09 Thread Alex Hall
Thanks to all for the quick responses. Python always surprises me with
its shortcuts...

On 12/9/10, Alan Gauld  wrote:
>
> "Alex Hall"  wrote
>
>> val=val or 1
>
>> I am guessing that val is an int. If val==0, the 'or' kicks in and
>> val=1, else the or is not needed and val=val. Am I close?
>
> Yes this is a combination of what is known as short circuit
> evaluation of boolean expressions and a quirk of Python that
> returns the actual value of something that is being treated as
> a boolean.
>
> There is a section on this in the Functional Programming
> topic in my tutor which explains and illustrates in much
> more detail.
>
> This particular trick is now deprecated in favour of the new
> conditional expressiion, so your code would now be written as:
>
> val = val if val else 1
>
>> Can other words or symbols be used in contexts where one
>> would not normally think of them?
>
> See my tutor, it shows how and can be used in similar ways...
>
> 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
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] 'or' in assignment (not if statement)?

2010-12-09 Thread Hugo Arts
On Fri, Dec 10, 2010 at 2:07 AM, Alan Gauld  wrote:
>
> "Alex Hall"  wrote
>>
>> val=val or 1
>
>> I am guessing that val is an int. If val==0, the 'or' kicks in and
>> val=1, else the or is not needed and val=val. Am I close?
>
> Yes this is a combination of what is known as short circuit evaluation of
> boolean expressions and a quirk of Python that returns the actual value of
> something that is being treated as a boolean.
>

Doesn't short-circuit evaluation refer specifically to the behavior
where arguments are only evaluated if they need to be? It's a very
useful feature, but not technically required for the "val = val or 1"
behavior to work.

Also, returning on of its operands rather than a boolean is hardly a
quirk, since basically all dynamic languages do it ever since perl
made "val = val or 1" an idiom (at least, I think it was perl).

There is more to the innocent little or. See
http://docs.python.org/library/stdtypes.html#truth-value-testing
It works on any type, not just numbers, and operates by truth value
testing, which is more complicated than it might first seem.

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


Re: [Tutor] 'or' in assignment (not if statement)?

2010-12-09 Thread Steven D'Aprano

Hugo Arts wrote:


Doesn't short-circuit evaluation refer specifically to the behavior
where arguments are only evaluated if they need to be? It's a very
useful feature, but not technically required for the "val = val or 1"
behavior to work.


Yes, exactly.

Some languages (Pascal comes to mind) doesn't have short-circuit 
behaviour at all. If I've understood correctly, some languages (Algol, I 
think, but don't quote me) have short-circuiting function parameters, so 
you could do this:


x = 0
function(flag, x/0)

and the argument x/0 would only be evaluated if the function actually 
tried to use it.


Python has short-circuit behaviour for:

x or y
x and y
all(iterable)
any(iterable)
true_value if condition else false_value



Also, returning on of its operands rather than a boolean is hardly a
quirk, since basically all dynamic languages do it ever since perl
made "val = val or 1" an idiom (at least, I think it was perl).


Yes, it's certainly useful and not deprecated. At worst, it's less 
common since the introduction of the ternary if operator, but it's still 
useful. You can do things like this:


extras = []  # Global list of extra names to use.

def func(x, names=None):
# Do something with x and an optional list of names.
names = names or extras or ['my', 'internal', 'list', 'of', 'names']
do_stuff_with(x, names)


This means that the names actually used will be the first of:

- the function argument
- the global extras
- the built-in internal list

which is not empty. So you can override the internal list globally by 
setting extras, and you can override the global list by passing a list 
of names to the function.




--
Steven

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


Re: [Tutor] Calling Program within Program

2010-12-09 Thread Modulok
Patty,

I didn't read through your code, but to call an external program see
the 'subprocess' module in the standard library:
http://docs.python.org/library/subprocess.html

-Modulok-


On 12/9/10, pa...@cruzio.com  wrote:
>
> Hello:
>
> I would like to know how to call a program from within a program and what
> directory I should place one small program file in.  I am running Python
> 2.6.6 and Windows 7.
>
> I have a directory called  C:\Users\StarShip\PyProgs and it has the files
> BreakersCafe.txt and BreakersCafe.py.  This is my primary program running
> fine.
>
> I have a subdirectory called C:\Users\StarShip\PyProg \PicturesForTesting
> and another subdirectory C:\Users\StarShip\PyProgs\CustomFunctions with
> various program files, functions defined  in them, etc.  which I import in
> my primary program.   For example:
>
>  def Newbanner():
> print "\n   Alternate Selections\n"
>
> Now I have the small program below which is fully self-contained and I
> want to execute it from within  BreakersCafe.txt. I would like to use
> raw_input and if statement for simple yes/no asking if they would like to
> see this BeveragesMenu.txt and have it as the last 3-4 lines of the
> main().
>
> The only directory of these three that has __init__ is
>C:\Users\StarShip\PyProgs\CustomFunctions
> and as you can see, the program below is not a function, it has no 'def'
> anything.  I get 'NameError: global name 'BeveragesMenu' is not defined'
> when I run this in IDLE.  I suppose I _could_ make this a function :} but
> it is likely doable to call a program as a program, right?  I am also
> compiling to a .pyw file where applicable.
>
> Thanks for the help.
>
> Patty
>
> """
> This is C:\Users\StarShip\PyProgs\BeveragesMenu.txt and BeveragesMenu.py.
> Program file for displaying an image using Tkinter built-in GUI functions.
>  open root window, open file descriptor for image, open new window file
> descriptor to manipulate with Tkinter Label library function.
>
> Pic needs to be displayed as a banner. Uses the compound="top" argument to
> do this.
>
> -->  take out the pack()function didn't work, pack()is required
>
> Uses   import Tkinter
>
> Program using new breaker's jpg picture; bar choices are not selectable
> """
>
>
> import Tkinter
> import ImageTk
>
> rootwindow = Tkinter.Tk()
>
> fhdl=
> ImageTk.Image.open("C:\Users\StarShip\PyProgs\PicturesForTesting\houseimage.jpg")
> image_var = ImageTk.PhotoImage(fhdl)
>
> whdl = Tkinter.Label(rootwindow, compound="top", image=image_var,
> text="\n\n!!!WELCOME TO BREAKER'S BREAKFAST BAR!!!\n\n\nBeverage Choices:
> Sparkling Water;  Milk;  Orange Juice;  Apple Juice  *OR*\n\n  **From Our
> Bar**Smoothie;  Breakers Sun Tea;  Chai;  Cafe Mocha;  Latte;
> Mimosa")
>
> whdl.pack()
> rootwindow.mainloop()
>
> ___
> 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