Suppose I have a module that I want to import called ImMod1 that's
saved in a variable like so:
var = "ImMod1"
Is there some way to import ImMod1 by using var?
Thanks,
Basu
--
The ByteBaker :
http://www.bytebaker.com
___
Tutor maillist - Tutor@python
I normally would use exceptions, because I think exceptions are a
great idea. But since the functions may be time-consuming graphics
functions and the lists could easily be hundreds of such calls, I
don't want the user to sit around for something that might fail. Of
course, I'm just starting so my
I have a list containing strings like :
func1[]
func2[1,2]
func3[blah]
I want to turn them into method calls (with numeric or string
arguments) on a supplied object. I'm trying to figure out the best way
to do this. Since these lists could be very big, and the methods could
be rather complex (mai
If you're just going to be using numbers as dictionary keys, it might
be simpler just to use a list structure. Dictionaries don't preserve
order, so you'd need to write extra code if you ever need to iterate
over it in order. Since your code increments field everytime it gets a
new record you can j
>From what I've seen, Lambda is most useful if you're passing functions
as arguments to other functions. You could use lambda to create a
function on-the-fly, as you've said, and that will save you the
trouble of having to write it separately. Try looking for examples on
functional programming in P
I'm working on a graph class to become more familiar with graphs in
general. I'd like to be able to do something like 'print gr' and get
something intelligible like a list of vertices. But using print on a
Graph class instance simply returns
Is there someway I can change what print prints?
--
T
My bad, should have included some code. Here's the function which does
the grunt work. self.axiom is a string, where each character gets
replaced by its counterpart from self.rules. output then goes back to
the calling function. That's the end of one generation of the string.
The next generation ha
I'm working on a program to create Lindenmayer systems. These systems
depend on heavy string rewriting to form complex patterns.I've been
using string concatenation to read through the string, and then create
the new one based on a dictionary lookup. However it becomes very slow
once the string get
Though I solved the problem by making database an instance variable,
there's one thing I'm curious about. If I 'overwrite' a class variable
with an instance one (as I did originally), is the class variable
recoverable? Will objects created later have the class or the instance
variable?
Basu
--
T
It turns out that Alan's catch of the instance vs class variables was
right. database was declared in the class body, rather than in the
__init__. Doing gram.database = {}, may have replaced it.. But I've
changed the Grammars class to have the proper instance variables.
Apparently my teammates and
Here's the relevant function:
def parse_display(self ):
try:
gram = Grammars(10, 10, self.pc_map, self.hard_rules)
gram.database = {}
for key, list in self.grammars.iteritems():
gram.addGram(key, list[0], list[1])
self.modules
I've been writing code where we have a class that does some basic
ordering and packaging of data we send in its constructor. Let's call
it Gen. At a particular point in our code we create an object:
genObject = Gen( someInt, someInt, aDict, aList)
genObject has a dictionary called dbase, which us
I've been writing a simple Tkinter interface to one of my programs.
But it looks rather bad on OS X leopard. I was wondering why that was
the case, since it seemed to take up at least some GUI elements (like
button styles). I then came upon the following page:
http://developer.apple.com/unix/toolki
Thanks for your suggestions, I've decided to go with the smart
iterator solution, it's given me the results that I need. The
generator solution also seems interesting and I might try it out at a
later point.
--
The ByteBaker :
http://www.bytebaker.com
___
If I do the following:
for item in block:
where block is a file, then item becomes each line of the file in turn
But if block in a large string (let's say the actual text that was in
the file), item becomes each character at a time. Is there a way to
have a uniform iteration irrespective of wheth
Our configuration language has evolved a bit more over the last few
days and I've decided to right a recursive descent parser for it.
Since this is a learning project for me, I'm writing the parser myself
instead of using one of the available packages. I'll see how this
affects the error handling.
Yes I am aware of the various Python parser packages. But at the
current moment the language is changing so I'm just writing a parser
as I go along. It probably isn't very good as it combines syntactical
analysis with some calculations as it goes along (which isn't really
good practice). Once the
I'm currently working on a research project where we'll be developing
a moderately complex piece of software. We're designing with
extensibility in mind. One of the problems I can see right now is that
our program can potentially create a large number of very different
errors, some fatal, some not.
Wow...I never expected to get so much help. Thanks for all of
it...it's much appreciated. I'm not quite sure which approach I'm
going to use (have quite some thinking to do), but I'll certainly
consider all of them. And I've certainly learned a lot.
Thanks again,
Basu
--
The ByteBaker :
http://w
The event handling approach looks interesting and isn't something that
I haven't encountered before. Could you to point me somewhere I could
learn more about it? I've already read the papers published by the
Pyro group and looked at some of their sample programs. I am trying to
give the user a simi
> This seems kind of strange to me. You want the entire user module to be
> re-run? Why don't you want looping and timing to be under the user's
> control? Can you show a short example of what the user code might look like?
>
> Kent
>
Well perhaps not the entire module, but probably most of i
I'm working on a module-based robot interface, but I've hit a bit of a
roadblock. I would like the user's script to be able to simply import
modules and drive the robot. I want the users code to be executed once
every few seconds, but I don't want the timing system to be part of
the users code: the
I have a dictionary (in a module) which contains values of various
sensors. I would like a user to be able use to a function syntax to
get the sensor values, both as a whole and individually. Currently I
have a function for each value who's sole purpose is to look up the
corresponding dict value an
Ok, I'm starting to understand how things work. Just one last
question: suppose my package has a config.py (which contains a config
dict) which another module in the package imports by "import config".
If the user of my package has a config.py in the directory from where
they run their program (whi
I'm not entirely sure about this, but I think for range(), the entire
range of numbers is generated at one go, which could cause a
slow-down. But xrange() generates the list of numbers one at a time.
For a thousand, there shouldn't be much of a difference, but if you
need a million or so go with xr
I'm working on a module consisting of a number of scripts that handle
communications over a serial connection. I would like someway for the
user to be able to specify which serial port to be used based on a
config file in the same directory as the user's program. Should I
place the parsing system i
Hi all,
I'd like to create a library of functions that would allow writing
Python scripts that would control a Hemisson robots via a serial
interface. I'll be using the pyserial module heavily, but I'm
wondering what would be the best way to approach this . Should I
create a "Robot" class and defin
27 matches
Mail list logo