Re: [Tutor] Fwd: Re: trouble placing code into wxpython

2012-02-02 Thread Alan Gauld

On 02/02/12 06:56, shane wrote:


i was trying to put the math.py into a frame Ive watched many tutorials.


That sounds like you've been using video tutorials? Those are a good 
start but you are probably better using a written one and working 
through them doing the examples. You can try my GUI topic as a quick 
start. It uses Tkinter but finishes with a wxPython version too so it 
might be enough to get you started. The concepts are similar.



But cant seem to find out how to or where to place the code
the files I want combined are attached.


#
import wx
app = wx.PySimpleApp()
frame = wx.Frame(None,-1,'hello')
frame.Show(1)
app.MainLoop()
#

This code creates the GUI(*) but does nothing.
You need to define the event handling functions and
bind them to the widgets/events. In this case you
don't have much to bind things to...

A Frame is just a container, it doesn't do anything as such.
You need to add other widgets such as text labels, entries,
buttons etc to the Frame. Then attach your functions
to the widgets. Any wxPython tutorial will show you
how to do that.

(*) wxPython is very OOP oriented, you normally have to create your own 
sub-class of Frame. There is not much you can do with a standard Frame 
object... If you are not comfortable with creating subclasses then you 
should study OOP a bit more before attempting wxPython. Either that or 
use Tkinter instead which is more amenable to procedural style code.


The other thing is your math code is full of print statements. They 
won't work in a GUI. You need to get your code to return strings and 
then display those strings in the GUI.


Finally, rewrite your fin() method to be non-recursive. Use a while 
loop. Otherwise you are likely to get into all sorts of trouble, its one 
of the most common beginners mistakes but recursion is not a good 
looping technique in Python. However, in a GUI you won't need fin() 
because the GUI mainloop will take over that function.


--
Alan G
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] Fwd: Re: trouble placing code into wxpython

2012-02-02 Thread Steven D'Aprano

shane wrote:


i was trying to put the math.py into a frame Ive watched many tutorials.
But cant seem to find out how to or where to place the code
the files I want combined are attached.


Do you mean you want to show the code in the GUI? You need to know the 
location of the file, then read the file and put the text into the frame. The 
fact that the text is actually code is irrelevant -- it could be poetry, a 
shopping list, code, or random gibberish.


I'm afraid I don't know enough about wxPython to tell you how to display text 
in the frame, but you can read the file like this:



fp = open(r'C:\path\to\my\file\module.py', 'r')
text = fp.read()
fp.close()


Also I see that you have a file called "math.py". That is a bad idea, because 
it will clash with a standard Python module also called "math". Best to find 
another name for it.




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


[Tutor] exercise with classes

2012-02-02 Thread Tonu Mikk
I am learning Python using the "Learn Python the Hard Way" book by Zed
Shaw.
 I reached exercise 42 where we learn about Python
classes.
 The exercise shows a game with one class that includes all the definitions
for playing the game.  For extra credit we are asked to create another
version of this game where we use two classes - one for the room
definitions and the other for the playing the game.  I feel stumped and
don't know how to go about creating this game with two classes.

So far I have searched for info on how to pass variables from one class to
another and have been able to create a small two class program (attached).
  But I seem unable to generalize from here and apply this to the game
exercise.  What would you suggest for me to try next?

Thank you,

Tonu


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


Re: [Tutor] exercise with classes

2012-02-02 Thread Prasad, Ramit
>I am learning Python using the "Learn Python the Hard Way" book by Zed Shaw.  
>I reached exercise 42 where we learn about Python classes.  The exercise shows 
>a game with one class that includes all the definitions for playing the game.  
>For extra credit we are asked to create another version of this game where we 
>use two classes - one for the room definitions and the other for the playing 
>the game.  I feel stumped and don't know how to go about creating this game 
>with two classes.
> So far I have searched for info on how to pass variables from one class to 
> another and have been able to create a small two class program (attached).   
> But I seem unable to generalize from here and apply this to the game 
> exercise.  What would you suggest for me to try next?  

It is usually better to include short code directly in your email 
or link to something like pastebin for longer samples. Many of the people
on this list do access it from email and they do not get attachments.

As for the extra credit: You can store the possible actions 
in the room (dodge, shoot, etc.). So for central_corridor (an instance
of class Room) you have the player do something like 

action = raw_input('>)
consequence = central_corridor.do_action( action )
new_room = Game.getRoom( consequence ) 
# Might need to replace Game with self depending on where this code is located.
action = raw_input('>)
consequence = new_room.do_action( action )
...


Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423

--

This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] better looping construct for replacing elements in file?

2012-02-02 Thread Brett Longworth

Hello,

Today I wrote a quick script to replace elements in multiple lines of a 
file with corresponding elements from a single line in another file, 
linking the two via an index element. The code iterates through the 
entire source file to find the matching index for each line of the 
destination file. This works, but it's clearly a terrible way to solve 
the problem. Can someone point me to a more efficient, pythonic solution?


thanks,
-Brett

Code:

wheel = "A794"
wheelfile = "A794.txt"
statusfile = "CURRENT.ams"

sfile = csv.reader(open(statusfile), delimiter='\t')
statusWriter = csv.writer(open('statustest.txt', 'wb'), delimiter='\t', 
quotechar='|', quoting=csv.QUOTE_MINIMAL)


for sline in sfile:
  #print sline
  wfile = csv.reader(open(wheelfile))
  for line in wfile:
#print line[0]
#print sline[18]
if line[0] == sline[18]:
  sline[0] = line [1]
  sline[1] = "OSG"+str(line[4])
  sline[17] = wheel
  sline[21] = line[9]
  statusWriter.writerow(sline)

Excerpt of wheelfile:

"2","X496","02/01/12","OSG","106788","85411","GS-13365","Outside Primary 
Standard | > Modern (1950)","2.43","149177"
"3","C655","02/01/12","OSG","106534","83028","HY-19231","Outside Blank | 
> 30,000","3.63","149178"


Excerpt of statusfile:

Y002BET291810/18/06 15:32:52160.001741.000
164081.306E-121.213E-10402.6405.9-42.73.2
1.2242-0.02201.822-12.66A499215631
86523data3.7E-6
Y002BET291810/18/06 15:35:46150.001621.000
156541.313E-121.226E-10407.6410.3-43.92.0
1.2180-0.02431.894-13.03A499215631
865233.7E-6
0003BET714710/18/06 15:55:33170.001861.000
34422.903E-132.693E-11357.7359.3-46.12.5
1.20000.02761.734-12.86A499315631
865243.3E-6
0003BET714710/18/06 15:58:49170.001851.000
32322.772E-132.598E-11351.8353.4-46.13.5
1.20000.01491.761-12.66A499315631
865243.2E-6
0003BET714710/18/06 16:02:06170.001851.000
33992.955E-132.753E-11346.9



--
Brett Longworth
Research Associate
Woods Hole Oceanographic Institution
ph: 508.289.3559
fax: 508.457.2183

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


Re: [Tutor] better looping construct for replacing elements in file?

2012-02-02 Thread Joel Goldstick
On Thu, Feb 2, 2012 at 3:50 PM, Brett Longworth  wrote:
> Hello,
>
> Today I wrote a quick script to replace elements in multiple lines of a file
> with corresponding elements from a single line in another file, linking the
> two via an index element. The code iterates through the entire source file
> to find the matching index for each line of the destination file. This
> works, but it's clearly a terrible way to solve the problem. Can someone
> point me to a more efficient, pythonic solution?
>
> thanks,
> -Brett
>
> Code:
>
> wheel = "A794"
> wheelfile = "A794.txt"
> statusfile = "CURRENT.ams"
>
> sfile = csv.reader(open(statusfile), delimiter='\t')
> statusWriter = csv.writer(open('statustest.txt', 'wb'), delimiter='\t',
> quotechar='|', quoting=csv.QUOTE_MINIMAL)
>
> for sline in sfile:
>  #print sline
>  wfile = csv.reader(open(wheelfile))
>  for line in wfile:
>    #print line[0]
>    #print sline[18]
>    if line[0] == sline[18]:
>      sline[0] = line [1]
>      sline[1] = "OSG"+str(line[4])
>      sline[17] = wheel
>      sline[21] = line[9]
>      statusWriter.writerow(sline)
>
> Excerpt of wheelfile:
>
> "2","X496","02/01/12","OSG","106788","85411","GS-13365","Outside Primary
> Standard | > Modern (1950)","2.43","149177"
> "3","C655","02/01/12","OSG","106534","83028","HY-19231","Outside Blank | >
> 30,000","3.63","149178"
>
> Excerpt of statusfile:
>
> Y002    BET2918    10/18/06 15:32:52    160.00    174    1.000    16408
>  1.306E-12    1.213E-10    402.6    405.9    -42.7    3.2    1.2242
>  -0.0220    1.822    -12.66    A499    2    1    5631    86523    data
>  3.7E-6
> Y002    BET2918    10/18/06 15:35:46    150.00    162    1.000    15654
>  1.313E-12    1.226E-10    407.6    410.3    -43.9    2.0    1.2180
>  -0.0243    1.894    -13.03    A499    2    1    5631    86523        3.7E-6
> 0003    BET7147    10/18/06 15:55:33    170.00    186    1.000    3442
>  2.903E-13    2.693E-11    357.7    359.3    -46.1    2.5    1.2000
>  0.0276    1.734    -12.86    A499    3    1    5631    86524        3.3E-6
> 0003    BET7147    10/18/06 15:58:49    170.00    185    1.000    3232
>  2.772E-13    2.598E-11    351.8    353.4    -46.1    3.5    1.2000
>  0.0149    1.761    -12.66    A499    3    1    5631    86524        3.2E-6
> 0003    BET7147    10/18/06 16:02:06    170.00    185    1.000    3399
>  2.955E-13    2.753E-11    346.9
>
>
> --
> Brett Longworth
> Research Associate
> Woods Hole Oceanographic Institution
> ph: 508.289.3559
> fax: 508.457.2183
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

If you are a little savvy with sql you could write each csv to tables,
Since you have csv file input why not write each to a db table.  Then
you could join on  line[0] == sline[18] and update your 4 fields.

Then dump table as csv

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


Re: [Tutor] better looping construct for replacing elements in file?

2012-02-02 Thread Brett Longworth

Hi Joel,

Thanks for the reply. The little voice in my head was yelling, "Easier 
with SQL!" the entire time, but I'm trying to learn Python.


-Brett

On 2/2/2012 4:16 PM, Joel Goldstick wrote:

On Thu, Feb 2, 2012 at 3:50 PM, Brett Longworth  wrote:

Hello,

Today I wrote a quick script to replace elements in multiple lines of a file
with corresponding elements from a single line in another file, linking the
two via an index element. The code iterates through the entire source file
to find the matching index for each line of the destination file. This
works, but it's clearly a terrible way to solve the problem. Can someone
point me to a more efficient, pythonic solution?

thanks,
-Brett

Code:

wheel = "A794"
wheelfile = "A794.txt"
statusfile = "CURRENT.ams"

sfile = csv.reader(open(statusfile), delimiter='\t')
statusWriter = csv.writer(open('statustest.txt', 'wb'), delimiter='\t',
quotechar='|', quoting=csv.QUOTE_MINIMAL)

for sline in sfile:
  #print sline
  wfile = csv.reader(open(wheelfile))
  for line in wfile:
#print line[0]
#print sline[18]
if line[0] == sline[18]:
  sline[0] = line [1]
  sline[1] = "OSG"+str(line[4])
  sline[17] = wheel
  sline[21] = line[9]
  statusWriter.writerow(sline)

Excerpt of wheelfile:

"2","X496","02/01/12","OSG","106788","85411","GS-13365","Outside Primary
Standard |>  Modern (1950)","2.43","149177"
"3","C655","02/01/12","OSG","106534","83028","HY-19231","Outside Blank |>
30,000","3.63","149178"

Excerpt of statusfile:

Y002BET291810/18/06 15:32:52160.001741.00016408
  1.306E-121.213E-10402.6405.9-42.73.21.2242
  -0.02201.822-12.66A49921563186523data
  3.7E-6
Y002BET291810/18/06 15:35:46150.001621.00015654
  1.313E-121.226E-10407.6410.3-43.92.01.2180
  -0.02431.894-13.03A499215631865233.7E-6
0003BET714710/18/06 15:55:33170.001861.0003442
  2.903E-132.693E-11357.7359.3-46.12.51.2000
  0.02761.734-12.86A499315631865243.3E-6
0003BET714710/18/06 15:58:49170.001851.0003232
  2.772E-132.598E-11351.8353.4-46.13.51.2000
  0.01491.761-12.66A499315631865243.2E-6
0003BET714710/18/06 16:02:06170.001851.0003399
  2.955E-132.753E-11346.9


--
Brett Longworth
Research Associate
Woods Hole Oceanographic Institution
ph: 508.289.3559
fax: 508.457.2183

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

If you are a little savvy with sql you could write each csv to tables,
Since you have csv file input why not write each to a db table.  Then
you could join on  line[0] == sline[18] and update your 4 fields.

Then dump table as csv




--
Brett Longworth
Research Associate
Woods Hole Oceanographic Institution
ph: 508.289.3559
fax: 508.457.2183

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


Re: [Tutor] better looping construct for replacing elements in file?

2012-02-02 Thread Joel Goldstick
On Thu, Feb 2, 2012 at 4:29 PM, Brett Longworth  wrote:
> Hi Joel,
>
> Thanks for the reply. The little voice in my head was yelling, "Easier with
> SQL!" the entire time, but I'm trying to learn Python.
>
> -Brett
>
>
> On 2/2/2012 4:16 PM, Joel Goldstick wrote:
>>
>> On Thu, Feb 2, 2012 at 3:50 PM, Brett Longworth
>>  wrote:
>>>
>>> Hello,
>>>
>>> Today I wrote a quick script to replace elements in multiple lines of a
>>> file
>>> with corresponding elements from a single line in another file, linking
>>> the
>>> two via an index element. The code iterates through the entire source
>>> file
>>> to find the matching index for each line of the destination file. This
>>> works, but it's clearly a terrible way to solve the problem. Can someone
>>> point me to a more efficient, pythonic solution?
>>>
>>> thanks,
>>> -Brett
>>>
>>> Code:
>>>
>>> wheel = "A794"
>>> wheelfile = "A794.txt"
>>> statusfile = "CURRENT.ams"
>>>
>>> sfile = csv.reader(open(statusfile), delimiter='\t')
>>> statusWriter = csv.writer(open('statustest.txt', 'wb'), delimiter='\t',
>>> quotechar='|', quoting=csv.QUOTE_MINIMAL)
>>>
>>> for sline in sfile:
>>>  #print sline
>>>  wfile = csv.reader(open(wheelfile))
>>>  for line in wfile:
>>>    #print line[0]
>>>    #print sline[18]
>>>    if line[0] == sline[18]:
>>>      sline[0] = line [1]
>>>      sline[1] = "OSG"+str(line[4])
>>>      sline[17] = wheel
>>>      sline[21] = line[9]
>>>      statusWriter.writerow(sline)
>>>
>>> Excerpt of wheelfile:
>>>
>>> "2","X496","02/01/12","OSG","106788","85411","GS-13365","Outside Primary
>>> Standard |>  Modern (1950)","2.43","149177"
>>> "3","C655","02/01/12","OSG","106534","83028","HY-19231","Outside Blank |>
>>> 30,000","3.63","149178"
>>>
>>> Excerpt of statusfile:
>>>
>>> Y002    BET2918    10/18/06 15:32:52    160.00    174    1.000    16408
>>>  1.306E-12    1.213E-10    402.6    405.9    -42.7    3.2    1.2242
>>>  -0.0220    1.822    -12.66    A499    2    1    5631    86523    data
>>>  3.7E-6
>>> Y002    BET2918    10/18/06 15:35:46    150.00    162    1.000    15654
>>>  1.313E-12    1.226E-10    407.6    410.3    -43.9    2.0    1.2180
>>>  -0.0243    1.894    -13.03    A499    2    1    5631    86523
>>>  3.7E-6
>>> 0003    BET7147    10/18/06 15:55:33    170.00    186    1.000    3442
>>>  2.903E-13    2.693E-11    357.7    359.3    -46.1    2.5    1.2000
>>>  0.0276    1.734    -12.86    A499    3    1    5631    86524
>>>  3.3E-6
>>> 0003    BET7147    10/18/06 15:58:49    170.00    185    1.000    3232
>>>  2.772E-13    2.598E-11    351.8    353.4    -46.1    3.5    1.2000
>>>  0.0149    1.761    -12.66    A499    3    1    5631    86524
>>>  3.2E-6
>>> 0003    BET7147    10/18/06 16:02:06    170.00    185    1.000    3399
>>>  2.955E-13    2.753E-11    346.9
>>>
>>>
>>> --
>>> Brett Longworth
>>> Research Associate
>>> Woods Hole Oceanographic Institution
>>> ph: 508.289.3559
>>> fax: 508.457.2183
>>>
>>> ___
>>> Tutor maillist  -  Tutor@python.org
>>> To unsubscribe or change subscription options:
>>> http://mail.python.org/mailman/listinfo/tutor
>>
>> If you are a little savvy with sql you could write each csv to tables,
>> Since you have csv file input why not write each to a db table.  Then
>> you could join on  line[0] == sline[18] and update your 4 fields.
>>
>> Then dump table as csv
>>
>
>
> --
> Brett Longworth
> Research Associate
> Woods Hole Oceanographic Institution
> ph: 508.289.3559
> fax: 508.457.2183
>

Even so, you would be learning how to do some simple sql things in
python.  It comes with sqlite3 so you don't even need to have mysql on
the machine

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


Re: [Tutor] better looping construct for replacing elements in file?

2012-02-02 Thread Peter Otten
Brett Longworth wrote:

> Hello,
> 
> Today I wrote a quick script to replace elements in multiple lines of a
> file with corresponding elements from a single line in another file,
> linking the two via an index element. The code iterates through the
> entire source file to find the matching index for each line of the
> destination file. This works, but it's clearly a terrible way to solve
> the problem. Can someone point me to a more efficient, pythonic solution?
> 
> thanks,
> -Brett
> 
> Code:
> 
> wheel = "A794"
> wheelfile = "A794.txt"
> statusfile = "CURRENT.ams"
> 
> sfile = csv.reader(open(statusfile), delimiter='\t')
> statusWriter = csv.writer(open('statustest.txt', 'wb'), delimiter='\t',
> quotechar='|', quoting=csv.QUOTE_MINIMAL)
> 
> for sline in sfile:
>#print sline
>wfile = csv.reader(open(wheelfile))
>for line in wfile:
>  #print line[0]
>  #print sline[18]
>  if line[0] == sline[18]:
>sline[0] = line [1]
>sline[1] = "OSG"+str(line[4])
>sline[17] = wheel
>sline[21] = line[9]
>statusWriter.writerow(sline)

You could put the data from wheelfile into a dictionary with the first 
column as the key, something like

import csv
from contextlib import contextmanager
from functools import partial

@contextmanager
def manager(mode, process, filename, **kw):
with open(filename, mode) as f:
yield process(f, **kw)

reader = partial(manager, "rb", csv.reader)
writer = partial(manager, "wb", csv.writer)

wheel = "A794"
wheelfilename = "A794.txt"
statusfilename = "CURRENT.ams"

wheel_lookup = {}
with reader(wheelfilename) as rows:
for row in rows:
key = row[0]
if key in wheel_lookup:
raise ValueError("duplicate key {}".format(key))
lookup[key] = row

with reader(statusfilename, delimiter="\t") as status_rows:
with writer("statustest.txt", delimiter="\t") as dest:
for status_row in status_rows:
key = status_row[18]
if key in lookup:
wheel_row = wheel_lookup[key]
status_row[0] = wheel_row[1]
status_row[1] = "OSG{}".format(wheel_row[4])
status_row[17] = wheel
status_row[21] = wheel_row[9]
dest.writerow(status_row)


I hope I didn't confuse the files or columns...

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


Re: [Tutor] exercise with classes

2012-02-02 Thread Alexander Etter
On Feb 2, 2012, at 12:36, Tonu Mikk  wrote:

>  I feel stumped and don't know how to go about creating this game with two 
> classes.
> 
> So far I have searched for info on how to pass variables from one class to 
> another and have been able to create a small two class program (attached). 

> Thank you,
> Tonu 
> 
> __
Hi Tonu. 
I'm fairly certain that your second class is missing the most important 
function of a class, the __init__ function! It's necessary to initialize the 
object. Add it to your second class and see how it changes things. 
Alexander___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] exercise with classes

2012-02-02 Thread Alan Gauld

On 02/02/12 17:36, Tonu Mikk wrote:


So far I have searched for info on how to pass variables from one class
to another and have been able to create a small two class program
(attached).   But I seem unable to generalize from here and apply this
to the game exercise.  What would you suggest for me to try next?


Remember that OOP is about creating objects from classes.
You can pass an object to another rather than just the
variables, in fact its preferable!

Also remember that you can create many objects from one class.
So just because you have one Room class doesn't mean you are
stuck with one room object. You can have many and each can
be connected to another.

You can get rooms to describe themselves, you can enter a room.
You might even be able to create new rooms or destroy existing ones. 
These actions can all be methods of your Room class.


Here is an example somewhat like yours that passes objects:

class Printer:
   def __init__(self,number=0):
  self.value = number
   def sayIt(self):
  print self.value

class MyApp:
   def __init__(self, aPrinter = None):
   if aPrinter == None: # if no object passed create one
  aPrinter = Printer()
   self.obj = aPrinter  # assign object
   def doIt()
   self.obj.sayIt() # use object

def test()
   p = Printer(42)
   a1  MyApp()
   a2 = MyApp(p)   # pass p object into a2
   a1.doIt()   # prints default value = 0
   a2.doIt()   # prints 42, the value of p

test()

HTH,

--
Alan G
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] better looping construct for replacing elements in file?

2012-02-02 Thread Alan Gauld

On 02/02/12 21:44, Joel Goldstick wrote:

On Thu, Feb 2, 2012 at 4:29 PM, Brett Longworth  wrote:

Hi Joel,

Thanks for the reply. The little voice in my head was yelling, "Easier with
SQL!" the entire time, but I'm trying to learn Python.


Even so, you would be learning how to do some simple sql things in
python.  It comes with sqlite3 so you don't even need to have mysql on
the machine



And you can run SQLite as an in-memory database so its even fast for 
temporary tables like this! (assuming you have enough RAM!)


HTH,

--
Alan G
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] any cons to using a module of functions?

2012-02-02 Thread Che M

I have a bunch of functions that do various utility-type tasks in an 
application (such as prettifying date strings, etc.), and they are used in many 
modules.  Much of the time, I have just been lazily copying and pasting the 
functions into whichever modules need them.  I realize that is very bad form 
and I should refactor, and so I am beginning to put these functions in their 
own module so that I can import the module and its functions when I need it; 
they will all be in one place and only only place.

My question is about resources.  Let's say I have the module, myUtils.py, and I 
import it into every other module that will need one or more of the functions 
within it.  Is this in any way costly in terms of memory?  (since each time I 
import myUtils.py I import *all* the functions, instead of in the cut&paste 
approach, where I just run the functions I need).

I'm fairly sure this is not at all an issue, but I just want to understand why 
it's not.  

Thanks.



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