473,386 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

A beginner's problem...

Hello everyone,

First, I have to say that Python is one of the coolest programing
languages I have seen.
And now for the problem (must be a silly one):
When I import a module I have wrote, and then I find bugs, it seems that
I can't import it again after a fix it. It always shows the same
problem. I try del module but it doesn't work.
(I use Python 2.4 with the ActivePython pack (PythonWin IDE)

Solution anyone?

Amir
Jul 18 '05 #1
9 1361
On Wed, 15 Dec 2004, Amir Dekel wrote:
Hello everyone,

First, I have to say that Python is one of the coolest programing languages I
have seen.
And now for the problem (must be a silly one):
When I import a module I have wrote, and then I find bugs, it seems that I
can't import it again after a fix it. It always shows the same problem. I try
del module but it doesn't work.
(I use Python 2.4 with the ActivePython pack (PythonWin IDE)

Solution anyone?


reload?

rday
Jul 18 '05 #2
In <cp**********@news.iucc.ac.il>, Amir Dekel wrote:
When I import a module I have wrote, and then I find bugs, it seems that
I can't import it again after a fix it. It always shows the same
problem. I try del module but it doesn't work.
(I use Python 2.4 with the ActivePython pack (PythonWin IDE)

Solution anyone?


Yes -> help(reload)

Ciao,
Marc 'BlackJack' Rintsch
Jul 18 '05 #3
"Marc 'BlackJack' Rintsch" <bj****@gmx.net> said:
In <cp**********@news.iucc.ac.il>, Amir Dekel wrote:
When I import a module I have wrote, and then I find bugs, it seems that
I can't import it again after a fix it. It always shows the same
problem. I try del module but it doesn't work.
(I use Python 2.4 with the ActivePython pack (PythonWin IDE)

Solution anyone?


Yes -> help(reload)

Ciao,
Marc 'BlackJack' Rintsch


First, save the file using the check option (Ctl+Shift+C, iirc);
Second, Fix any errors (attend to Status Bar);
Third, press Reload button in Toolbar (or type command from File Menu).
Four, assure that Status Bar indicates reload was successful.
If still doesn't load correctly, quit PythonWin and start it again.
Jul 18 '05 #4
DogWalker wrote:
"Marc 'BlackJack' Rintsch" <bj****@gmx.net> said:

In <cp**********@news.iucc.ac.il>, Amir Dekel wrote:

When I import a module I have wrote, and then I find bugs, it seems that
I can't import it again after a fix it. It always shows the same
problem. I try del module but it doesn't work.
(I use Python 2.4 with the ActivePython pack (PythonWin IDE)

Solution anyone?


Yes -> help(reload)

Ciao,
Marc 'BlackJack' Rintsch

First, save the file using the check option (Ctl+Shift+C, iirc);
Second, Fix any errors (attend to Status Bar);
Third, press Reload button in Toolbar (or type command from File Menu).
Four, assure that Status Bar indicates reload was successful.
If still doesn't load correctly, quit PythonWin and start it again.

Fifth, use the module unittest and write a test for your module. Just
run the test to check your module and fix all errors, then import it
into the larger sceme and see if everything works there. Most problems
will appear in a good test, so you will not have the reimport issiue at all.
Chris
Jul 18 '05 #5
Try deleting the Compiled Python File that was created during import --
extension pyc. Then import again.

It seems to me (I'm a novice too) that, when you import a module, Python
automatically compiles it. Then when you import it later, the compiled
version is imported if it exists.
"Amir Dekel" <ad****@ort.org.il> wrote in message
news:cp**********@news.iucc.ac.il...
Hello everyone,

First, I have to say that Python is one of the coolest programing
languages I have seen.
And now for the problem (must be a silly one):
When I import a module I have wrote, and then I find bugs, it seems that
I can't import it again after a fix it. It always shows the same
problem. I try del module but it doesn't work.
(I use Python 2.4 with the ActivePython pack (PythonWin IDE)

Solution anyone?

Amir

Jul 18 '05 #6
[Format recovered from top posting.]

"James Martin" <sf*****@POPworldnet.att.net> writes:


"Amir Dekel" <ad****@ort.org.il> wrote in message
news:cp**********@news.iucc.ac.il...
Hello everyone,
First, I have to say that Python is one of the coolest programing
languages I have seen.
And now for the problem (must be a silly one):
When I import a module I have wrote, and then I find bugs, it seems that
I can't import it again after a fix it. It always shows the same
problem. I try del module but it doesn't work.
(I use Python 2.4 with the ActivePython pack (PythonWin IDE)

Solution anyone?

Try deleting the Compiled Python File that was created during import --
extension pyc. Then import again.

It seems to me (I'm a novice too) that, when you import a module, Python
automatically compiles it. Then when you import it later, the compiled
version is imported if it exists.


It compares the dates on the .py file with the .pyc file, and
recompiles the .py file if it's newer.

Doing a second import will find the module in sys.modules and not
bother looking in the file system. The solution is to reload(module)
instead of import module.

<mike
--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Jul 18 '05 #7
Mike Meyer wrote:

Doing a second import will find the module in sys.modules and not
bother looking in the file system. The solution is to reload(module)
instead of import module.

<mike

What if I import using "from module import class"? It seems to me that I
can't use reload then, or I just couldn't find the right syntax...
Jul 18 '05 #8
Amir Dekel <ad****@ort.org.il> writes:
Mike Meyer wrote:
Doing a second import will find the module in sys.modules and not
bother looking in the file system. The solution is to reload(module)
instead of import module.
<mike

What if I import using "from module import class"? It seems to me that
I can't use reload then, or I just couldn't find the right syntax...


I'm pretty sure you'll have to import the module and reload it. "from
module import class" still puts the module in sys.modules, so trying
to import something from it again will find it in there.

<mike
--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Jul 18 '05 #9
Amir Dekel wrote:
Mike Meyer wrote:

Doing a second import will find the module in sys.modules and not
bother looking in the file system. The solution is to reload(module)
instead of import module.

<mike


What if I import using "from module import class"? It seems to me that I
can't use reload then, or I just couldn't find the right syntax...


Correct. Using a non-from import is actually easier when experimenting, since
reload is easier to use.

If you have used a from-style import, you have to do this to force a reload of
the relevant class:

Py> from module import x
Py> # Do stuff
Py> import module
Py> reload(module)
Py> from module import x
Py> # We now have the updated version of x

Cheers,
Nick.

--
Nick Coghlan | nc******@email.com | Brisbane, Australia
---------------------------------------------------------------
http://boredomandlaziness.skystorm.net
Jul 18 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: jvax | last post by:
Hi all, I hope I'm posting in the right NG... I have a data text file I want to read from a c++ program. the data file goes like this: 90 # number of balls 33 42 13
5
by: Richard B. Kreckel | last post by:
Hi! I was recently asked what book to recommend for a beginner in C++. I am convinced that you needn't study C in depth before learning C++ (though it helps), but cannot find any beginner's...
18
by: mitchellpal | last post by:
Hi guys, am learning c as a beginner language and am finding it rough especially with pointers and data files. What do you think, am i being too pessimistic or thats how it happens for a beginner?...
20
by: weight gain 2000 | last post by:
Hello all! I'm looking for a very good book for an absolute beginner on VB.net or VB 2005 with emphasis on databases. What would you reccommend? Thanks!
10
by: See_Red_Run | last post by:
Hi, I am trying to figure out how to get started with PHP/MySQL. Everything I've read so far says to start with PHP first. I was expecting something like Visual Basic Express or some other type...
4
by: Bails | last post by:
Hi Im an absolute beginner in programming and am using VB.Net Express. To start my larning I decided to do a "Real World" app instead of "hello world" and am creating a Poker Countdown clock. ...
5
by: macca | last post by:
Hi, I'm looking for a good book on PHP design patterns for a OOP beginner - Reccommendations please? Thanks Paul
10
by: Roman Zeilinger | last post by:
Hi I have a beginner question concerning fscanf. First I had a text file which just contained some hex numbers: 0C100012 0C100012 ....
1
by: H. Fraser | last post by:
I've downloaded all of the code and video dealing with the RSS Reader but when i try to run it, it throws an exception, saying 404 page not found. And, As a total beginner, i've no idea where...
22
by: ddg_linux | last post by:
I have been reading about and doing a lot of php code examples from books but now I find myself wanting to do something practical with some of the skills that I have learned. I am a beginner php...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.