"dynamical" importing

2005-10-19 Thread Joerg Schuster
Hello,

I need to import modules from user defined paths. I.e. I want to do
something
like:

module_dir = sys.argv[1]

my_path = os.path.join(module_dir, 'bin', 'my_module')

from my_path import my_object

Obviously, it doesn't work this way. How would it work?

Jörg Schuster

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "dynamical" importing

2005-10-19 Thread Joerg Schuster
Thanks a lot to all.

-- 
http://mail.python.org/mailman/listinfo/python-list


more than 100 capturing groups in a regex

2005-10-24 Thread Joerg Schuster
Hello,

Python regular expressions must not have more than 100 capturing
groups. The source code responsible for this reads as follows:


# XXX:  get rid of this limitation!
if p.pattern.groups > 100:
raise AssertionError(
"sorry, but this version only supports 100 named groups"
)

I have been waiting a long time now for Python to get rid of this
limitation.
I could make a program of mine a lot faster with an easy hack if Python
did not have it.

My question is: Does anyone know if the problem is going to be fixed in
the next few months or so? Or is there a way to circumvent it?


Jörg Schuster

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: more than 100 capturing groups in a regex

2005-10-25 Thread Joerg Schuster
> Some people, when confronted with a problem, think "I know,
> I'll use regular expressions." Now they have two problems.
> --Jamie Zawinski

Thanks for the citation.

If my goal had been to redesign my program, I would not ask questions
about regular expressions. I do not have the time to redesign my
program. And knowing that my situation would be better, if I had
written other code in the past, does not help me at all.

I just want to use more than 100 capturing groups. If someone told me
that it is very unlikely for Python to get rid of the said limitation,
I would recode part of my program in C++ using pcre. But I would prefer
to be able to do everything in Python. That is why I asked.

Jörg

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: more than 100 capturing groups in a regex

2005-10-25 Thread Joerg Schuster
> What happens if you up the limit to whatever you need?

Good idea. I just tried this. Nothing evil seems to happen. This seems
to be a solution. Thanks.

Jörg

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: more than 100 capturing groups in a regex

2005-10-25 Thread Joerg Schuster
No limitation at all would be best. If a limitation is necessary, then
the more capturing groups, the better. At the time being, I would be
really happy about having the possibility to use 1 capturing
groups.

Jörg

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: more than 100 capturing groups in a regex

2005-10-25 Thread Joerg Schuster
> but what is the reason for so much capturing groups?  I
> imagine that coding this and keeping code maintenable is a huge effort.

User input is compiled to regular expressions. The user does not have
to worry about those groups.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: more than 100 capturing groups in a regex

2005-10-25 Thread Joerg Schuster
> The joys of open source. Just remember you have now
> made your program
> non-portable. Hope this isn't an issue.

Of course portability is an issue -- on the long run. But on the short
run I am really glad to be able to do a 1 second demo run on my
notebook instead of a 20 seconds demo run. And I am especially glad to
get this 1 second demo by doing a 30-minute hack. (Hopefully ...)

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: more than 100 capturing groups in a regex

2005-10-25 Thread Joerg Schuster
You did not quite understand me. I will give you some details:

My program is a compiler for a certain type of linguistic grammars.
I.e. the user gives *grammar files* to my program. When the grammar
files have been compiled, they can be applied to strings (of a certain
language, e.g. English).

In the grammar files, the user does not have to deal with "capturing
groups". He even does not have to deal with regular expressions. He
just writes a grammar of a certain type. My program then compiles the
grammar into a cascade of transducers. Each of the transducers is
internally represented as a pair (REGEX, ACTION), where REGEX is a
Python regular expression and ACTION a Python function. I.e.: The
meaning of the grammar is: For each line of the input string: if REGEX
matches the line, then apply ACTION to it.

On various levels, the user may produce *disjunctions*. At the time
being, these disjunctions are internally represented by something like:

if regex1: action1()
elif regex2: action2()
elif ...
eliif regexn: actionn()

It would be nicer (and faster) to have just one regex and run that
action A such that the *capturing group* with name A ("?P...")
matched.

Now, I could of course internally create my very own transducers. But
the re module is a module that generates fsa and fsa do part of the
work that a transducer does. So why reinvent the wheel? 


Jörg

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: more than 100 capturing groups in a regex

2005-10-26 Thread Joerg Schuster
> if you want to know why 100 is a reasonable and non-random choice, I
> suggest checking the RE documentation for "99 groups" and the special
> meaning of group 0.

I have read everything I found about Python regular expressions. But I
am not able to understand what you mean. What is so special about 99?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: more than 100 capturing groups in a regex

2005-10-26 Thread Joerg Schuster
So what?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: more than 100 capturing groups in a regex

2005-10-26 Thread Joerg Schuster
My first test program was far too naive. Evil things do happen. Simply
removing the code that restricts the number of capturing groups to 100
is not a solitution.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: more than 100 capturing groups in a regex

2005-10-26 Thread Joerg Schuster
... solution

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: more than 100 capturing groups in a regex

2005-10-27 Thread Joerg Schuster
> It's a conflict between python's syntax for regex back
> references and
> octal number literals.  Probably wasn't noticed until way
> too late, and
> now it will never change.

So "reasonable choice" is not a really good description of the
phenomenon.

-- 
http://mail.python.org/mailman/listinfo/python-list


os.system()

2005-03-07 Thread Joerg Schuster
Hello,

code like

os.system(command)

only works for some values of 'command' on my system (Linux). A certain
shell command (that *does* run on the command line) does not work when
called with os.system(). Does anyone know a simple and stable way to
have *any* string executed by the shell?

Jörg Schuster

--
http://mail.python.org/mailman/listinfo/python-list


Re: os.system()

2005-03-07 Thread Joerg Schuster
Well, I can give you the string, but that will not help:

transduce abc info_dic comp_dic input_file output_file

For copy right reasons, I am not allowed to give you the program
transduce.

But here are some facts about transduce:

- it is written in C
- it takes an alphabet file (abc) and two automata files (info_dic and
comp_dic) as input and applies the automata files to the input file.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.system()

2005-03-07 Thread Joerg Schuster
> Several variables like PATH "normally" get reset even when
> running a non-login subshell

It seems that this has been the problem. I guess your tip saved me a
lot of time. Thanks a lot.

Joerg

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.system()

2005-03-07 Thread Joerg Schuster
> Several variables like PATH "normally" get reset even when
> running a non-login subshell

It seems that this has been the problem. I guess your tip saved me a
lot of time. Thanks a lot.

Joerg

-- 
http://mail.python.org/mailman/listinfo/python-list


shuffle the lines of a large file

2005-03-07 Thread Joerg Schuster
Hello,

I am looking for a method to "shuffle" the lines of a large file.

I have a corpus of sorted and "uniqed" English sentences that has been
produced with (1):

(1) sort corpus | uniq > corpus.uniq

corpus.uniq is 80G large. The fact that every sentence appears only
once in corpus.uniq plays an important role for the processes
I use to involve my corpus in.  Yet, the alphabetical order is an
unwanted side effect of (1): Very often, I do not want (or rather, I
do not have the computational capacities) to apply a program to all of
corpus.uniq. Yet, any series of lines of corpus.uniq is obviously a
very lopsided set of English sentences.

So, it would be very useful to do one of the following things:

- produce corpus.uniq in a such a way that it is not sorted in any way
- shuffle corpus.uniq > corpus.uniq.shuffled

Unfortunately, none of the machines that I may use has 80G RAM.
So, using a dictionary will not help.

Any ideas?

Joerg Schuster

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: shuffle the lines of a large file

2005-03-07 Thread Joerg Schuster
Thanks to all. This thread shows again that Python's best feature is
comp.lang.python.

Jörg

--
http://mail.python.org/mailman/listinfo/python-list


compile shebang into pyc file

2005-04-26 Thread Joerg Schuster
Hello,

is there a way to compile a python file foo.py to foo.pyc (or foo.pyo)
such that foo.pyc can be run with 'foo.pyc' (as opposed to 'python
foo.pyc') on the command line?

Jörg Schuster

--
http://mail.python.org/mailman/listinfo/python-list


Re: compile shebang into pyc file

2005-04-27 Thread Joerg Schuster
> #!/usr/bin/env python
> import app

Yes, of course this is a possibility. But it implies having (or giving
away) two files.

I think having one file is always better than having two files. Because
if you have two files, you need a third one: a README that tells you
what to do with the two files and that one of the files must either be
in $PYTHONPATH, or in the same directory as the other one and '.' must
be in your $PYTHONPATH , and so on. Actually, some people will also
need a fourth file: One that contains an explanation of terms like
"$PYTHONPATH" and the like. 

Jörg

--
http://mail.python.org/mailman/listinfo/python-list


Re: compile shebang into pyc file

2005-04-28 Thread Joerg Schuster
> so you're saying that the set of people that can deal with
> no more than one
> file at a time but knows how to install and configure Python
> (which in itself
> comes with a few thousand files) is larger than zero?

Take me as an example: Very often, I needed software that could solve a
specific problem. I used to find, say, 10 different packages. Usually
none of the programs REALLY did the job as I wanted it to be done. Yet,
in order to find this out (or in order to find the package that suited
my needs best), I had to try out all of these packages. This used to
take an unnecessary amount of time.

I would have found (say) one java program, one c++ program, one Python
program, one perl program, ...

I know that java, c++, Python and Perl are all installed on our system.
And if they weren't, I would know how to install them myself: By using
yast or by saying 'apt-get install '.

Yet: I don't want to have to know how to install all these packages in
all these different languages. I think a program should work out of the
box. And the should be no fumbling it out of the box.

Jörg

--
http://mail.python.org/mailman/listinfo/python-list


open file in dir independently of operating system

2005-05-25 Thread Joerg Schuster
Hello,


I want to open the file 'configuration.smo' that is in directory dir.
Yet, I don't know on which os my program is being run. On Unix I would
say:

f = open(dir + '/configuration.smo', 'r')

What is the os-independent version of this line?

(I have read the manual of the module os, but I didn't see how to do
it.)


Jörg Schuster

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: open file in dir independently of operating system

2005-05-25 Thread Joerg Schuster
Thanks, Andrew and Gerald.

Jörg

-- 
http://mail.python.org/mailman/listinfo/python-list