472,976 Members | 1,395 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

my parser.py isn't imported

Hallöchen!

I have a module parser.py in the same directory as the main module.
In the main module, I import "parser". On Linux, this works as
expected, however on Windows, it imports the stdlib parser module.
sys.path[0] points to the directory of my parser.py in both cases.
What went wrong here?

Tschö,
Torsten.

--
Torsten Bronger, aquisgrana, europa vetus
Jabber ID: br*****@jabber.org
(See http://ime.webhop.org for ICQ, MSN, etc.)
Aug 26 '07 #1
1 1513
Hallöchen!

John Machin writes:
Torsten Bronger wrote:
>I have a module parser.py in the same directory as the main
module. In the main module, I import "parser". On Linux, this
works as expected, however on Windows, it imports the stdlib
parser module. sys.path[0] points to the directory of my
parser.py in both cases. What went wrong here?

[...]

2. Failure to RTFabulousM:
"""
Details of the module searching and loading process are implementation
and platform specific. It generally involves searching for a ``built-
in'' module with the given name and then searching a list of locations
given as sys.path.
"""
Okay, I did the following to avoid this:

import sys, os.path
modulepath = os.path.abspath(os.path.dirname(sys.argv[0]))
def import_local_module(name):
"""Load a module from the local modules directory.

Loading e.g. a local "parser" module is difficult because on
Windows, the stdlib parser module is a built-in and thus loaded
with higher priority. With
http://www.python.org/dev/peps/pep-0328/ it may become simpler.

:Parameters:
- `name`: name of the module, as it would be given to
``import``.

:Return:
the module object or ``None`` if none was found

:rtype:
module
"""
import imp
try:
return sys.modules[name]
except KeyError:
pass
fp, pathname, description = imp.find_module(name, [modulepath])
try:
return imp.load_module(name, fp, pathname, description)
finally:
# Since we may exit via an exception, close fp explicitly.
if fp:
fp.close()

Tschö,
Torsten.

--
Torsten Bronger, aquisgrana, europa vetus
Jabber ID: br*****@jabber.org
(See http://ime.webhop.org for ICQ, MSN, etc.)
Aug 27 '07 #2

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

Similar topics

13
by: Paulo Pinto | last post by:
Hi, does anyone know of a Python package that is able to load XML like the XML::Simple Perl package does? For those that don't know it, this package maps the XML file to a dictionary.
3
by: Himanshu Garg | last post by:
Hello, I am trying to pinpoint an apparent bug in HTML::Parser. The encoding of the text seems to change incorrectly if the locale isn't set properly. However Parser.pm in the directory...
3
by: Markus Dehmann | last post by:
Sorry, this is slightly offtopic, but: Given a C++ header file, how can I get information about all the member functions of the contained classes, with information about the return types and...
5
by: qqcq6s59 | last post by:
Hi all I am a newbie and I just saw a ongoing thread on Fileprocessing which talks abt config parser. I have writen many pyhton program to parse many kind of text files by using string module and...
5
by: Bill Cunningham | last post by:
In comp.programming I asked for advice for writing a parser. The code someone showed me wouldn't compile. I don't know what's wrong. I just want to write the simpliest of parsers. int...
2
by: Joel Hedlund | last post by:
Hi! I have a possibly dumb question about imports. I've written two python modules: parser.py ------------------------------------ class Parser(object): "my parser"...
2
by: Alex | last post by:
Hello all, As I don't have any experience with XML parsers, I'm looking for your advice in this group. In the project I'm involved with, we are dealing with parsing of XML messages that are...
28
by: Marc Gravell | last post by:
In Linq, you can apparently get a meaningful body from and expression's .ToString(); random question - does anybody know if linq also includes a parser? It just seemed it might be a handy way to...
6
by: Herby | last post by:
Hi, Im interested in Reverse Engineering C++ source code into a form more comprehensible than the source itself. I want to write a basic one myself, obviously i need to write a parser for the...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
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...
2
isladogs
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...
0
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...
4
NeoPa
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 :...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
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...
4
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...

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.