Re: Is Python worth it??
http://www.norvig.com/21-days.html -- bytecolor -- http://mail.python.org/mailman/listinfo/python-list
Re: module to parse "pseudo natural" language?
Andrew E wrote: > Hi all > > I've written a python program that adds orders into our order routing > simulation system. It works well, and has a syntax along these lines: > > ./neworder --instrument NOKIA --size 23 --price MARKET --repeats 20 > > etc > > However, I'd like to add a mode that will handle, say: > > ./neworder buy 23 NOKIA at MKT x 20 > > I could enter several orders either by running multiple times, or use a > comma-separated approach, like: > > ./neworder buy 23 NOKIA at MKT on helsinki, sell 20 NOKIA at market on > helsinki You could add a string option instead: $ neworder -c 'buy 23 NOKIA at MKT on helsinki, sell 20 NOKIA at market on helsinki' This would leave your current option parsing in tact. Then just split on the comma. Another suggestion would be to drop into an interactive mode if no arguments are passed: $ neworder ->? buy 23 NOKIA at MKT on helsinki ->? sell 20 NOKIA at market on helsinki ->? ^d > The thing about this is that its a "tolerant" parser, so all of these > should also work: > > # omit words like "at", "on" > ./neworder buy 23 NOKIA mkt helsinki > > # take any symbol for helsinki > ./neworder buy 23 mkt helsinki > > # figure out that market=helsinki > ./neworder buy 23 NOKIA at market price > > > I've started writing a simple state-based parser, usage like: > > class NaturalLanguageInsructionBuilder: > > def parse( self, arglist ): > """Given a sequence of args, return an Instruction object""" > ... > return Instruction( instrument, size, price, ... ) > > > class Instruction: > """encapsulate a single instruction to buy, sell, etc""" > > def __init__( self, instrument, size, price, ... ): > ... > > > This doesn't work yet, but I know with time I'll get there. > > Question is - is there a module out there that will already handle this > approach? > > Thanks for any suggestions :) > > Andrew If I were in your situation, I'd probably write a BNF for the tiny-language. This would help wrap my brain around the problem. The BNF would help show what kind of regular expression you are looking at creating as well. -- bytecolor -- http://mail.python.org/mailman/listinfo/python-list
Re: some suggestions about GUI toolkits?
I recently wrote a small application using wxPython (my first with this GUI). I've used it on Windows XP, Debian GNU/Linux (sarge) and OS X (Panther). The application only uses a few widgets but it wasnt difficult at all to get up and running. -- bytecolor -- http://mail.python.org/mailman/listinfo/python-list
instance references?
I'm working on a simple graphics package. I've got a function show() that the user needs to call at the end of the script to actually display the points, lines and circles that have been defined in the script. p1 = point(0, 0) l1 = line(1, 3, -4, 5) c1 = circle(-2, 3, 1) show() In each __init__() method of the point, line, and circle objects I add self to a list in a separate module, then show() uses this list to actually draw the objects. This works except: l1 = line(point(1, 3), point(-4, 5)) c1 = circle(point(-2, 3), 1) adds the references to the points used to define the objects to the render list. I only want objects that have been assigned to a variable to be rendered. (Try to ignore the function overloading.) So how can I tell if an instance of point, line or circle has actually been assigned to a variable? -- bytecolor -- http://mail.python.org/mailman/listinfo/python-list
Re: instance references?
Thanks Alex, the weak references *seem* to be doing what I want for now. In each __init__() I use: aptbase.drawables.append(weakref.ref(self)) Then in show(): for d in aptbase.drawables: o = d() if o is not None: # render it -- bytecolor -- http://mail.python.org/mailman/listinfo/python-list
package_data question
I have a simple package. I'm trying to add an examples subdirectory with distutils. I'm using Python 2.4 on Linux. My file layout and setup.py can be found here: http://www.deadbeefbabe.org/paste/3870 I've tried using data_files as well, with the same result; examples/ fig2.3.apt is not added to the tarball. -- bytecolor -- http://mail.python.org/mailman/listinfo/python-list
Re: package_data question
On Mar 5, 3:52 pm, "Goldfish" <[EMAIL PROTECTED]> wrote: > On Mar 5, 1:56 am, "bytecolor" <[EMAIL PROTECTED]> wrote: > I have a package along with a samples section. I have both a setup.py > script along with a MANIFEST.in file to make sure everything gets in. > You can see both of the files > athttps://springpython.python-hosting.com/browser/trunk/samples http://tinyurl.com/yo3qqo > > That is for the samples section. For my main package, I have something > similar athttps://springpython.python-hosting.com/browser/trunk/src -- http://mail.python.org/mailman/listinfo/python-list
Tkinter <> and bindtags ordering
I'm trying to extract the text of the current line on the <>
event.
It doesnt work if I delete a character. If I type 'abc' I get 'abc' in
text_changed().
If I hit backspace I still get 'abc'. Backspace once more, I get 'ab'.
So the
callback is called before the text is changed. But only on a delete.
Someone told me it has to do with bindtags ordering. I've read what
docs I can
find on the subject, but I cant figure out why it's not working. Maybe
I should
learn a bit of Tcl, eh?
import Tkinter as tk
def text_changed(evt):
global changing
if changing: return
changing = True
line, col = t.index('insert').split('.')
txt = t.get('%s.0' % line, '%s.end' % line)
print '|%s|' % txt
t.tk.call(t._w, 'edit', 'modified', 0)
changing = False
changing = False
root = tk.Tk()
t = tk.Text(master=root)
t.pack()
t.focus_set()
t.tk.call(t._w, 'edit', 'modified', 0)
t.bind('<>', text_changed)
root.mainloop()
--
bytecolor
--
http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter <> and bindtags ordering
On Apr 3, 3:16 am, "Rob Wolfe" <[EMAIL PROTECTED]> wrote:
> What about instead of:
>
> > t.bind('<>', text_changed)
>
> this event:
>
>t.bind('', text_changed)
>
> > root.mainloop()
>
> --
> HTH,
> Rob
Hey Rob,
I actually started with that event, until I came across the modified
event. I'm working on syntax highlighting. So I need any text change.
Also, colorizing on a key release is annoyingly noticeable to the
user. I tried it :)
I'm sure there are going to be other perils along the way as this is
my first attempt at syntax highlighing. I can load a file and the
highlighting works very well. I used an elaborate regex with named
groups and re.finditer(). I either use the names directly as edit
tags, or they help me look up other tags in a dict. It's quite fast.
screenshot with random (ugly) colors:
http://bytecolor.homelinux.org/~bytecolor/vapt_colorizing.png
That part wasn't bad at all. Now I need to code the text change
logistics but this bindtags ordering has got me perplexed.
--
bytecolor
--
http://mail.python.org/mailman/listinfo/python-list
Re: Parsing Problems
On Apr 3, 5:13 am, [EMAIL PROTECTED] wrote:
> Hi,
>
> I have just started learning python.I need to parse an XML file
> and present the contents in a particular format.The format is called
> as "ini" file.I have written some code.A section of the format needs
> the data to be present in format as given below:
>
> [Services]
> supported=0x10,0x1A,0x3B,0x20,0x27,0x28,0x34,0x36,0x3E,0xA2,0xA5,0x2D,
> 0x22,0xA9,0x04,0xAA,0xAE
>
> My code for this section parses the xml file and gives :
> [Services]
> Supported=['0x3e', '0x28', '0x3b', '0x22', '0x20', '0x27', '0xaa',
> '0x10', '0xae', '0x34', '0x36', '0x2d', '0xa9', '0xa5', '0x4', '0xa2',
> '0x1a']
>
> {forget the numericals matching}.As you can see there
> are single quotes around numericals ,which is not desired .I think the
> problem lies in me using a list for storing and later printing out
> values.I have attached few lines of code,not sure how clear it can be
> to you:
>
> for l in range(0,len(ser_par),
> 1):
> if
> ser_par[l].getAttribute('Semantics')==u'serviceId':
> if
> tag_exists(ser_par[l].childNodes,'VALUE'):
> val =
> ser_par[l].getElementsByTagName('VALUE')
> value =
> str(val[0].getAttribute('value'))
> valu = hex(int(value))
> rval.append(valu)
> ser_par_num = ser_par_num + 1
> prim_num = prim_num + 1
>
> service_num = service_num + 1
> variant_num = variant_num + 1
> ser = list(set(rval))
>
> print "\n[Services]"
> print "Supported="+str(ser)
>
> How can i get rid of those single quotes.
>
> Thanking you
>
> shakeel
>>> l = ['0x3e', '0x28', '0x3b', '0x22', '0x20', '0x27', '0xaa']
>>> ','.join(l)
'0x3e,0x28,0x3b,0x22,0x20,0x27,0xaa'
You may want to look at the ConfigParser package too. It's for reading/
writing .ini file.
--
bytecolor
--
http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter <> and bindtags ordering
On Apr 3, 5:48 am, "Rob Wolfe" <[EMAIL PROTECTED]> wrote: > Have you looked at ColorDelegator.py from idlelib? > There has been done such a syntax highlighting based on Tkinter.Text. > > -- > HTH, > Rob I've been poking around it a bit. I actually use the tabpage module in my app. Guess I should take a harder look at it. Nice bit of software. -- bytecolor -- http://mail.python.org/mailman/listinfo/python-list
win32com short path name on 2k
Hi people,
Using win32com on 2k SP3...
>>> import win32com.client as w32c
>>> fc = w32c.Dispatch('Featurecam.Application')
>>> fc.InstallPath
u'C:\\PROGRA~1\\FEATUR~1'
>>>
Using win32com on XP Professional SP2...
>>> import win32com.client as w32c
>>> fc = w32c.Dispatch('Featurecam.Application')
>>> fc.InstallPath
u'C:\\Program Files\\FeatureCAM'
>>>
Why the short vs long names?
--
bytecolor
--
http://mail.python.org/mailman/listinfo/python-list
Re: win32com short path name on 2k
I have no idea how Featurecam registers the type library. I did figure out that I can get the full name 'C:\Program Files\Featurecam' from within Featurecam using VBA and the same property I used in Pyhton -> fc.InstallPath. Why would VBA and Python return two different strings? This is really driving me nuts, because I know for a fact I was getting the long name using python on 2k not 3 days ago, but now it's returning the short name and I haven't changed/installed anything. -- bytecolor -- http://mail.python.org/mailman/listinfo/python-list
Re: win32com short path name on 2k
Thanks Russell, those funcs sound familiar. I've probably used them or, more than likely, read about them in the past. -- bytecolor -- http://mail.python.org/mailman/listinfo/python-list
