Hi, folks,
At the beginning of 2003, I was a frustrated computer user, and lapsed
programmer, with problems to solve that screamed for programming.
Thanks to the Python language and community, I am a programmer once
again.
My earlier solicitation to the computer world is here: http://groups.google.com/groups?selm...ing.google.com
Anyway, I've been busy with Python for several months now. I'm an old
procedural guy. I had never written code in an object-oriented
language before. I'm starting to get the hang of it, and to see its
advantages, but I'm still struggling. I think that I have issues with
both OOP in general, and with Python in particular.
I have written one nice, self-contained object that contained a DNA
sequence, and various functions to manipulate the data therein. My
wxPython GUI objects, in contrast, are in a state of constant flux.
Rather than importing and reusing a piece of code, I find myself
copying the code into my new program and playing with it, just a bit.
I'm starting to believe that writing a good GUI object, one that you
can really reuse, is actually quite hard. Yes, I know that you can
derive a new object that overrides properties of your old object.
Should I find myself doing this for every object that I write?
One other thing -- I would like to be able to include a statement in
my program to the effect of: "from my_package import
my_function_or_class". Python seems to look for .pyc files in the
/Lib folder. By placing a .py file in /Lib, I got it to compile, and
to be recognized by an import statement. Is this the right way for
users to package their own code? It seems kludgy to me.
If it matters (it shouldn't), I'm running Python 2.2.2 on Win2000 Pro.
Thanks for your advice!
--
John J. Ladasky Jr., Ph.D.
Department of Biology
Johns Hopkins University
Baltimore MD 21218
USA
Earth 5 2603
> One other thing -- I would like to be able to include a statement in my program to the effect of: "from my_package import my_function_or_class". Python seems to look for .pyc files in the /Lib folder. By placing a .py file in /Lib, I got it to compile, and to be recognized by an import statement. Is this the right way for users to package their own code? It seems kludgy to me.
AFAIK if you want to import a python module (actually *.py file), you
can place it in /Lib subdirectory of python distribution, but I think
this subdirectory schould better stay reserved for modules from standard
python distribution.
You can put your module in any directory, and then add this subdirectory
to the PYTHONPATH environment variable of your operating system. I've
been doing this for a while, but then I ended with unmanageable cluster
of files distributed somewhere on my computer.
I think the best way is to use distutilities (Distributing Python
Modules link in your python documentation). I've studied it a few days
ago, and it is much easier to use (at least for simple things) than I
had thought before.
There is also a /lib/site-packages directory in your python
distribution, if you put your *.py file in it, you can allways import it
in your application, and it is also intended as directory for
third-party python modules, and distutilities will install your modules
into this subdirectory. I 'd recommend you to use packages (section 6.4
Packages in the tutorial in your python documentation) if you are not
allready doing so, because otherwise you'll probably soon get name
clashes.
If you use distutillities, you get two extras too:
1. You can easily make a Windows installer for your library, and if you
install your library this way, it will be registerd by OS, so if you
want to uninstall your library, you can do it as for any other windows
programm.
2. If you want to compile C extension, the easiest way to do so is with
distutilities. The first time I succeeded to do so, was with help from
some web post by Alex Martelli (maybe it is in Python recepies, but I'm
not sure). Most information how to do this is rather linux oriented.
Actually it is not difficult to do so on Windows (also with Mingw
compiler) but there is, AFAIK, no detailed (from begin to end at one
place) instruction how to do it for dummies (I still feel like one, so
the worst thing that can happen is a hint: "look into your compiler
documentation"), it is rather distributed over the web.
I have written one nice, self-contained object that contained a DNA sequence, and various functions to manipulate the data therein. My wxPython GUI objects, in contrast, are in a state of constant flux. Rather than importing and reusing a piece of code, I find myself copying the code into my new program and playing with it, just a bit. I'm starting to believe that writing a good GUI object, one that you can really reuse, is actually quite hard. Yes, I know that you can derive a new object that overrides properties of your old object. Should I find myself doing this for every object that I write?
I do not feel competent enough to give much advice here, but I believe
that, if you start to copy and paste your code, you should reconsider
your design. But, on the other hand, if you intend your library to be
used by others, to many classes and inheritance can be cumbersome. I
remember trying to use some Java library, which can do great things, but
in order to do simplest things with it, I schould use dozen classes,
where each of them was e.g. 5-th or 10-th in some inheritance hierarchy,
and you can imagine the fun of finding documentation of the
class-methods I wanted to use. I can not judge if it is OK for complex
library which is intended to be used by professional programmers.
At the beginning of 2003, I was a frustrated computer user, and lapsed programmer, with problems to solve that screamed for programming. Thanks to the Python language and community, I am a programmer once again.
I am actualy weather forecaster, and I do some programming in my spare
time. I can remember learning C++ for about 6-7 months, and then
learning Java for about 3-4 months, and still not beeing able to open
text file and do some simple processing (which I could have done easily
in Fortran77 before) without looking in a book . The best advice I've
found in the book "Thinking in Java", was to have a look at Python.
Marijan Tadin
On Fri, 2003-10-24 at 02:15, John Ladasky wrote: I have written one nice, self-contained object that contained a DNA sequence, and various functions to manipulate the data therein. My wxPython GUI objects, in contrast, are in a state of constant flux. Rather than importing and reusing a piece of code, I find myself copying the code into my new program and playing with it, just a bit. I'm starting to believe that writing a good GUI object, one that you can really reuse, is actually quite hard. Yes, I know that you can derive a new object that overrides properties of your old object. Should I find myself doing this for every object that I write?
John ,
I see you've been helped with the /Lib folder question. I am more
interested to hear about your GUI problem. I don't use wxPython I use
Tkinter but hardly ever find myself copying code from one project to
another...(these days) perhaps you could share some examples of the kind
of GUI elements you find yourself copying...
One example I used to find myself copying would be a tool bar (Tkinter
does not have a 'toolbar' widget) I would find myself creating a Frame
then adding lots of buttons to it now however I use a Toolbar class I
created that has an add method that takes a couple of arguments.
e.g (untested) I now use something like:
class Toolbar(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
def add(self, label="", icon=None, command=None):
b = Button(self, text=label, command=command, image=icon)
b.pack(side="left")
.... now to use it in some other module...
tb = Toolbar(root)
tb.pack(fill="x")
tools = [("Open", None, self.openFile),
("Close", None, self.closeFile),
("Quit", None, self.quit)
]
for label, image, command in tools:
tb.add(label=label, icon=image, command=command)
## rather than...
toolbar = Frame(parent)
toolbar.pack()
openButton = Button(toolbar, text="Open", command=self.openFile)
openButton.pack(side="left")
closeButton = Button(toolbar, text="Close", command=self.closeFile)
closeButton.pack(side="left")
.... you get the picture...
Is this the sort of problem you are having..?
Regards
Martin
--
Martin Franklin <mf********@gatwick.westerngeco.slb.com>
John Ladasky wrote: Hi, folks,
[snip] One other thing -- I would like to be able to include a statement in my program to the effect of: "from my_package import my_function_or_class". Python seems to look for .pyc files in the /Lib folder. By placing a .py file in /Lib, I got it to compile, and to be recognized by an import statement. Is this the right way for users to package their own code? It seems kludgy to me.
If it matters (it shouldn't), I'm running Python 2.2.2 on Win2000 Pro.
Thanks for your advice!
-- John J. Ladasky Jr., Ph.D. Department of Biology Johns Hopkins University Baltimore MD 21218 USA Earth
You can put your modules anywhere you like. You just need to tell the
Python interpreter where to look for them. You can do this one of two
ways, either by setting a PYTHONPATH environment variable; http://www.python.org/doc/current/tu...00000000000000
Do this on Windows 2000 with Start->Settings->Control Panel->System
Then select the 'Advanced' tab and click on the button labelled
"Environment variables..."
Or, you can use path configuration (.pth) files; http://www.python.org/doc/current/lib/module-site.html
On Windows 2000, and with Python installed to C:\Python2.2 you would
place your file (called, say John.pth) in C:\Python2.2\Lib\site-packages
Regards,
Andy
--
--------------------------------------------------------------------------------
From the desk of Andrew J Todd esq - http://www.halfcooked.com/
"John Ladasky" <la*****@my-deja.com> wrote in message
news:c0*************************@posting.google.co m... Hi, folks,
At the beginning of 2003, I was a frustrated computer user, and lapsed programmer, with problems to solve that screamed for programming. Thanks to the Python language and community, I am a programmer once again.
My earlier solicitation to the computer world is here:
http://groups.google.com/groups?selm...ing.google.com Anyway, I've been busy with Python for several months now. I'm an old procedural guy. I had never written code in an object-oriented language before. I'm starting to get the hang of it, and to see its advantages, but I'm still struggling. I think that I have issues with both OOP in general, and with Python in particular.
I have written one nice, self-contained object that contained a DNA sequence, and various functions to manipulate the data therein. My wxPython GUI objects, in contrast, are in a state of constant flux. Rather than importing and reusing a piece of code, I find myself copying the code into my new program and playing with it, just a bit. I'm starting to believe that writing a good GUI object, one that you can really reuse, is actually quite hard. Yes, I know that you can derive a new object that overrides properties of your old object. Should I find myself doing this for every object that I write?
I'd suggest you look at refactoring out duplication. What it sounds like
is that you're generating a lot of minor variations on the same theme.
If you go after duplication relentlessly, eventually the code itself will
tell you what it wants to look like.
Thanks for your advice!
You're welcome.
John Roth -- John J. Ladasky Jr., Ph.D. Department of Biology Johns Hopkins University Baltimore MD 21218 USA Earth
Not sure if ya'll have seen these references to distutils and windows. I'm
forwarding to make sure we keep it in mind when we're working on our book.
Anna
On Fri, 24 Oct 2003 07:01:52 +0100, Marijan Tadin wrote: One other thing -- I would like to be able to include a statement in my program to the effect of: "from my_package import my_function_or_class". Python seems to look for .pyc files in the /Lib folder. By placing a .py file in /Lib, I got it to compile, and to be recognized by an import statement. Is this the right way for users to package their own code? It seems kludgy to me.
AFAIK if you want to import a python module (actually *.py file), you can place it in /Lib subdirectory of python distribution, but I think this subdirectory schould better stay reserved for modules from standard python distribution. You can put your module in any directory, and then add this subdirectory to the PYTHONPATH environment variable of your operating system. I've been doing this for a while, but then I ended with unmanageable cluster of files distributed somewhere on my computer. I think the best way is to use distutilities (Distributing Python Modules link in your python documentation). I've studied it a few days ago, and it is much easier to use (at least for simple things) than I had thought before. There is also a /lib/site-packages directory in your python distribution, if you put your *.py file in it, you can allways import it in your application, and it is also intended as directory for third-party python modules, and distutilities will install your modules into this subdirectory. I 'd recommend you to use packages (section 6.4 Packages in the tutorial in your python documentation) if you are not allready doing so, because otherwise you'll probably soon get name clashes. If you use distutillities, you get two extras too: 1. You can easily make a Windows installer for your library, and if you install your library this way, it will be registerd by OS, so if you want to uninstall your library, you can do it as for any other windows programm. 2. If you want to compile C extension, the easiest way to do so is with distutilities. The first time I succeeded to do so, was with help from some web post by Alex Martelli (maybe it is in Python recepies, but I'm not sure). Most information how to do this is rather linux oriented. Actually it is not difficult to do so on Windows (also with Mingw compiler) but there is, AFAIK, no detailed (from begin to end at one place) instruction how to do it for dummies (I still feel like one, so the worst thing that can happen is a hint: "look into your compiler documentation"), it is rather distributed over the web.
I have written one nice, self-contained object that contained a DNA sequence, and various functions to manipulate the data therein. My wxPython GUI objects, in contrast, are in a state of constant flux. Rather than importing and reusing a piece of code, I find myself copying the code into my new program and playing with it, just a bit. I'm starting to believe that writing a good GUI object, one that you can really reuse, is actually quite hard. Yes, I know that you can derive a new object that overrides properties of your old object. Should I find myself doing this for every object that I write?
I do not feel competent enough to give much advice here, but I believe that, if you start to copy and paste your code, you should reconsider your design. But, on the other hand, if you intend your library to be used by others, to many classes and inheritance can be cumbersome. I remember trying to use some Java library, which can do great things, but in order to do simplest things with it, I schould use dozen classes, where each of them was e.g. 5-th or 10-th in some inheritance hierarchy, and you can imagine the fun of finding documentation of the class-methods I wanted to use. I can not judge if it is OK for complex library which is intended to be used by professional programmers.
At the beginning of 2003, I was a frustrated computer user, and lapsed programmer, with problems to solve that screamed for programming. Thanks to the Python language and community, I am a programmer once again.
I am actualy weather forecaster, and I do some programming in my spare time. I can remember learning C++ for about 6-7 months, and then learning Java for about 3-4 months, and still not beeing able to open text file and do some simple processing (which I could have done easily in Fortran77 before) without looking in a book . The best advice I've found in the book "Thinking in Java", was to have a look at Python.
Marijan Tadin This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Christian Seberino |
last post by:
How does Ruby compare to Python?? How good is DESIGN of Ruby compared to Python?
Python's design is godly. I'm wondering if Ruby's is godly too.
I've heard it has solid OOP design but then...
|
by: David MacQuigg |
last post by:
I'm concerned that with all the focus on obj$func binding, &closures,
and other not-so-pretty details of Prothon, that we are missing what
is really good - the simplification of classes. There are...
|
by: Nick Evans |
last post by:
Hello there,
I have been on and off learning to code (with python being the second
language I have worked on after a bit of BASIC). What I really want to know
is, if you are going to actually...
|
by: Jerald |
last post by:
Running python 2.3.4 on valgrind (a tool like purify which checks
the use of uninitialized memory, etc), gives a lot of errors.
See below.
jfj@cluster:~/> python -V
Python 2.3.4...
|
by: Stumped and Confused |
last post by:
Hello,
I really, really, need some help here - I've spent hours trying to find a
solution.
In a nutshell, I'm trying to have a user input a value in form's
textfield. The value should then be...
|
by: Levi Campbell |
last post by:
Hi, I'm thinking about writing a system for DJing in python, but I'm
not sure if Python is fast enough to handle the realtime audio needed
for DJing, could a guru shed some light on this subject...
|
by: Raj |
last post by:
Hi,
We just executed a project with Python using TG. The feedback was to
use more python like programming rather than C style code executed in
Python. The feedback is from a Python purist and...
|
by: Sai Krishna M |
last post by:
Hi everybody,
i have been developing web based applications using python+cheetah.
The numbers are increasing. The applications have many common parts of
code. Though these applications are...
|
by: MisterPete |
last post by:
I created an object that inherits from file and was a bit surprised to
find that print seems to bypass the write method for objects
inheriting from file. An optimization I suppose. Does this...
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
| |