Re: Python Web Site?

2006-10-17 Thread Michael B. Trausch
Tim Chase wrote:
>> Is there a problem with the Python and wxPython web sites?
>> I cannot seem to get them up
> 
> Sounds like someone needs some pyagra...
> 
> (grins, ducks, and runs)
> 

Interesting.  I thought at first it was a problem with Python's sites...
but I got through to the Python site just now... but I can't get through
to the wx* sites (wxwidgets.org, wxpython.org at the very least).  Seems
that my trouble with the Python web site itself was coincidental.

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


Attempting to parse free-form ANSI text.

2006-10-21 Thread Michael B. Trausch
Alright... I am attempting to find a way to parse ANSI text from a
telnet application.  However, I am experiencing a bit of trouble.

What I want to do is have all ANSI sequences _removed_ from the output,
save for those that manage color codes or text presentation (in short,
the ones that are ESC[#m (with additional #s separated by ; characters).
 The ones that are left, the ones that are the color codes, I want to
act on, and remove from the text stream, and display the text.

I am using wxPython's TextCtrl as output, so when I "get" an ANSI color
control sequence, I want to basically turn it into a call to wxWidgets'
TextCtrl.SetDefaultStyle method for the control, adding the appropriate
color/brightness/italic/bold/etc. settings to the TextCtrl until the
next ANSI code comes in to alter it.

It would *seem* easy, but I cannot seem to wrap my mind around the idea.
 :-/

I have a source tarball up at http://fd0man.theunixplace.com/Tmud.tar
which contains the code in question.  In short, the information is
coming in over a TCP/IP socket that is traditionally connected to with a
telnet client, so things can be broken mid-line (or even mid-control
sequence).  If anyone has any ideas as to what I am doing, expecting, or
assuming that is wrong, I would be delighted to hear it.  The code that
is not behaving as I would expect it to is in src/AnsiTextCtrl.py, but I
have included the entire project as it stands for completeness.

Any help would be appreciated!  Thanks!

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


Re: Attempting to parse free-form ANSI text.

2006-10-23 Thread Michael B. Trausch
Jean-Paul Calderone wrote:
> On Sun, 22 Oct 2006 00:34:14 -0400, "Michael B. Trausch"
>  wrote:
>> Alright... I am attempting to find a way to parse ANSI text from a
>> telnet application.  However, I am experiencing a bit of trouble.
>>
>> What I want to do is have all ANSI sequences _removed_ from the output,
>> save for those that manage color codes or text presentation (in short,
>> the ones that are ESC[#m (with additional #s separated by ; characters).
>> The ones that are left, the ones that are the color codes, I want to
>> act on, and remove from the text stream, and display the text.
> 
> http://originalgamer.cvs.sourceforge.net/originalgamer/originalgamer/originalgamer/ansi.py?revision=1.12&view=markup
> may be of some interest.
> 

I am attempting to study this code to see how it does it.  From what I
can see of this thread, it appears to be one of many solutions.
Unfortunately, I am not well-versed in this whole application
programming thing... .  I can do simple things, and am good at web
apps, but this style of things is quite new for me.

Anyway, we'll see what I can get out of that, and maybe I can find the
solution.  Thanks for the pointer!

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


Re: Attempting to parse free-form ANSI text.

2006-10-23 Thread Michael B. Trausch
Frederic Rentsch wrote:
> Michael B. Trausch wrote:
>> Alright... I am attempting to find a way to parse ANSI text from a
>> telnet application.  However, I am experiencing a bit of trouble.
>>
[snip]
>
> *I have no experience with reading from TCP/IP. But looking at your
> program with a candid mind I'd say that it is written to process a chunk
> of data in memory.
>

That would be correct... that's the only way that I can think of to do
it, since the chunks come in from the network to a variable.

>
> If, as you say, the chunks you get from TCP/IP may
> start and end anywhere and, presumably you pass each chunk through
> AppendText, then you have a synchronization problem, as each call resets
> your escape flag, even if the new chunk starts in the middle of an
> escape sequence. Perhaps you should cut off incomplete escapes at the
> end and prepend them to the next chunk.
>

The question would be -- how does one determine if it is incomplete or
not?  The answer might lie in the previous response to this, where there
is another ANSI python module that works with the text.  Actually, it's
possible that my entire approach is faulty -- I am, after all, a rather
newbie programmer -- and this is my first go at an application that does
something other than "Hello, world!"

> 
> And:
> 
> if(len(buffer) > 0): 
> wx.TextCtrl.AppendText(self, buffer)  <<< Are you sure text goes
> into the same place as the controls?
>

What do you mean?  This function is in AnsiTextCtrl (so, it is
AnsiTextCtrl.AppendText).  I have derived AnsiTextCtrl from wx.TextCtrl,
so I think that if I need to call the parent's function, I would do so
directly, with 'self' being the current object, and buffer being the
text to add from the network.

When I call AppendText from an instance of a text control, (e.g.,
AnsiTextCtrl.AppendText(buffer)), I don't need to provide the object
that needs to be worked on.  It seems to work okay; but I know that just
because something works okay, that doesn't mean it is right.  So, am I
doing it wrong?

>   if(len(AnsiBuffer) >
> 0):   wx.TextCtrl.AppendText(self, AnsiBuffer)  <<<
> You say you want to strip the control sequences
> 

Yes, in the end I do.  Right now, I had to see what was going on.  I
figure that once I do figure out how to get it working, I can see the
color changes when the ANSI code shows up in the buffer, and they should
match up with the little chart that I have of the codes here.
Hopefully.  And then I can stop printing the extra crud on here.

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


Python segmentation fault?

2006-10-23 Thread Michael B. Trausch
Is there a way to debug scripts that cause segmentation faults?  I can
do a backtrace in gdb on Python, but that doesn't really help me all
that much since, well, it has nothing to do with my script... :-P

Any ideas?

Thanks,
Mike
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Attempting to parse free-form ANSI text.

2006-10-24 Thread Michael B. Trausch
Jean-Paul Calderone wrote:
> On Sun, 22 Oct 2006 00:34:14 -0400, "Michael B. Trausch"
>  wrote:
>> Alright... I am attempting to find a way to parse ANSI text from a
>> telnet application.  However, I am experiencing a bit of trouble.
>>
>> What I want to do is have all ANSI sequences _removed_ from the output,
>> save for those that manage color codes or text presentation (in short,
>> the ones that are ESC[#m (with additional #s separated by ; characters).
>> The ones that are left, the ones that are the color codes, I want to
>> act on, and remove from the text stream, and display the text.
> 
> http://originalgamer.cvs.sourceforge.net/originalgamer/originalgamer/originalgamer/ansi.py?revision=1.12&view=markup
> may be of some interest.
> 

This was actually very useful.  I was able to cleanly implement this for
a subset of ANSI colors.  I have to figure out yet how to get bold
implemented the way that ANSI users expect it to be, but that shouldn't
be that hard.  I am just going to have to rework the way that I handle
colors for the TextCtrl widget, since it assumes that bold really means
to overstrike the text as to make it bold.

Thanks!
Mike
-- 
http://mail.python.org/mailman/listinfo/python-list


Debugging/Networking ?s.

2006-10-26 Thread Michael B. Trausch
I am having a little bit of trouble figuring out what to do about a
problem that I am having with the program I am working with.

I had it working yesterday, and up through till this morning.  I hadn't
thought about putting it in version control until now, so whatever it
was I did, I can't just hit a revert button... that'll teach me.  :-)

Anyway, it opens a socket, and is capable of fetching the first output
from it and displaying it in the TextCtrl that it is using.  It also
says that it is successfully sending what is typed, be it an alias for
something else, or a straight command that needs to be sent.  However,
after the initial text is received, it says that it doesn't receive anymore.

I would believe that, if I could duplicate it with a known working
program (such as telnet)... but, I can't.  The server that I am working
with is working perfectly fine -- e.g., it is replying just as it should
be.  However, it is also not detecting any problem with the socket,
either.  :-/

The code is at http://fd0man.theunixplace.org/Tmud.tar.gz and if someone
could give me some insight as to what I might be doing wrong in
PlayWindow.py, method CheckAndProcessGameOutput, that would be
wonderfully appreciated.  I am out of ideas, myself.  It never comes up
with error, and never says that the socket is ready, either (using
select.select()).

Beware that the code isn't likely to be very pretty -- I am not an
experienced programmer.  Even some of the ideas I got from the ANSI
thread are likely to look not so pretty, because I probably mangled a
lot of that, too, though, it *was* working.  The only thing that
irritates me is that the changes I have been working on today have all
been in the SendOut method in PlayWindow.py, which should have no
bearing on CheckAndProcessGameOutput, so I don't know what really caused
it to stop working.

Thanks in advance for any assistance!

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


PyDev + Eclipse (Was: Re: What's the best IDE?)

2006-10-26 Thread Michael B. Trausch
Kenneth McDonald wrote:
>
> With the most recent edition of PyDev, I find Eclipse works quite well
> for me.
> 

Since you mentioned it, I have a question that searching around and
poking around has not solved for me, yet.

Do you have auto-completion working with your setup?  It does not seem
to work at all for me.  I have read through the configuration help, and
there are no firewalls on my system at all, and everything else works
save for auto-completion, which I have had to disable.  If left enabled,
even with low timeouts, I have to kill Eclipse and start it again.  :-/

Other than that, I find that it is absolutely wonderful.  I have used
Eclipse in the past for PHP based projects, and intend on using it for
Java projects in the future (my school has Java classes in its
curriculum instead of C classes... joy).

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


Re: PyDev + Eclipse (Was: Re: What's the best IDE?)

2006-10-26 Thread Michael B. Trausch
olive wrote:
> 
> Did you try to set your PYTHONPATH properly with the same content in
> both central AND project preferences ?
> 

Yep.  Still does it.  And the kicker is, that it does it with things
that it shouldn't have to wonder terribly much about -- classes that I
have custom-built, where it can easily find the available methods and
the like.  *shrugs*

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


Re: which one of these is better?

2006-10-26 Thread Michael B. Trausch
John Salerno wrote:
> def create_sql_script(self):
> try:
> with open('labtables.sql') as sql_script:
> return sql_script.read()
> except IOError:
> wx.MessageBox('Could not locate the file "labtables.sql"',
>   'File Not Found')
> 

I can't comment on this, because it won't work in my implemention of
Python, I don't think.

> 
> OR
> 
> 
> def create_sql_script(self):
> try:
> f = open('labtables.sql')
> sql_script = f.read()
> except IOError:
> wx.MessageBox('Could not locate the file "labtables.sql"',
>   'File Not Found')
> finally:
> f.close()
> 

Not really über-qualified to say anything, but I think that the
following would be better:

try:
f = open('file.sql')
script = f.read()
f.close()
except IOError:
wx.MessageBox('Message', 'Message Title')

> 
> Do they both do the same thing?
>

Not sure about the with-- I just went to read the PEP on it, and it
confused me greatly.  :-)  So, I don't know.

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

Re: Python segmentation fault?

2006-10-26 Thread Michael B. Trausch
Klaas wrote:
> Michael B. Trausch wrote:
>> Is there a way to debug scripts that cause segmentation faults?  I can
>> do a backtrace in gdb on Python, but that doesn't really help me all
>> that much since, well, it has nothing to do with my script... :-P
> 
> Yes.  If you think it is a python interpreter bug, create a
> self-contained script which reproduces the issue, and file a python bug
> report.
> 
> I'd be interested to see the stack trace--I recently uncovered a
> segfault bug in python2.5 and I might be able to tell you if it is the
> same one.
> 

I finally found out what the problem was -- I was using something that
was in the wx.* set of classes and functions, and it was the item
segfaulting.  I was apparently making an assumption or doing something
wrong, though I didn't have this project in Subversion at the time so I
can't say exactly which changes fixed it.  I have it in Subversion now,
though, so that in the future I can be sure to better find out what is
going on by having all of the information handy.

Thanks for the help!

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


Tracing the execution of scripts?

2006-10-26 Thread Michael B. Trausch
Alright, I seem to be at a loss for what I am looking for, and I am not
even really all that sure if it is possible or not.  I found the 'pdb'
debugger, but I was wondering if there was something that would trace or
log the order of line execution for a multi-module Python program.  I am
having a little bit of a problem tracking down a problem that I
mentioned earlier
(http://groups.google.com/group/comp.lang.python/msg/9c759fc888b365be),
and I am hoping that maybe seeing how the statements are executed will
shed some light on the entire thing for me.

The debugger isn't working, though, because I have a timer set up to
fire off every 20ms to check for incoming network traffic from the
server, and that timer firing off makes stepping through with the
debugger seemingly impossible to get any useful data.

Basically, is there something that will log every line of Python code
executed, in its order of execution, to a text file so that I can see
what is (or isn't) happening that I am expecting?  I know that the
server is sending and receiving properly, because I can connect to it
with a regular telnet client and it works -- but at the same time,
everything I can think of to check my program's functionality checks out
just fine (e.g., it reports that it is successfully sending what I am
typing to the server, and it says that the server is not sending
anything back to be read from the socket).

If it makes any difference, I am using wxWidgets' Python bindings for
the UI code (and the timer), and using Python's socket library for the
network stuff.

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


Re: Tracing the execution of scripts?

2006-10-27 Thread Michael B. Trausch
Jean-Paul Calderone wrote:
> 
> In order of importance:
> 
> 1) Write unit tests for your code.  Keep writing unit tests until you have
> some that _don't pass_.  Then fix your code so that they do.  When you do
> further development, write the tests first, then implement the code that
> makes them pass.
> 

Perhaps I could use some pointers on that.  I have read the bits and
pieces that I have found regarding unit testing in the past, and I have
wrote "unit tests" for things that I have done, but mostly for pieces of
reusable code that interact with other programs.

And I still have to wrap my mind around the idea of test first, develop
later.  It's fully possible that this works for many, but my (admittedly
few) attempts at that methodology have failed me.  I have a problem
writing something without reference to look at while writing it -- so if
I am writing something, say, to test my AnsiTextCtrl, I would need to
look at the AnsiTextCtrl to see what methods and such I should be testing.

That having been said, I don't have the slightest clue how a unit test
would be written for something that is purely user oriented, anyway.  I
was under the impression that unit tests were automated little tests
that required no user intervention to perform, right?

Actually, thinking about the idea of unit tests, I have found a few
resources online that generically talk about unit tests.  Even the books
that I have read on programming talk about unit tests.  However, all the
generic-ness with which the subject is approached makes my head spin.
(It does that a lot when I am trying to learn something new, by the way.)

>
> 2) Don't use threads.  At least have a way to not use threads while you're
> debugging.  Debugging with threads is very difficult. (Actually I'm not
> sure
> if you're using threads.  If you're not, feel free to ignore this point.)
> 

Fortunately, I am not.  At least, I don't think I am, unless wxWidgets
uses them internally or something.  Threading would make my head explode
at this point.  I really am used to just pulling off simple, sysadmin
type things using massive subsets of languages to just "get things done."

>
> 3) Don't poll for network events every 20ms.  If you have a sensible event
> loop you'll find debugging and testing much easier.
> 

I don't know what you mean.  I believe wxWidgets handles the looping.
And, as least, as far as I could tell with the documentation, the wx
networking API is not exposed to Python.  The "event loop" that you are
describing is, I am assuming, the MainLoop which gets started for wx.App
derived objects?

>
> 4) Use an existing library instead of developing a new one.
>

I had looked for one, at least for the AnsiTextCtrl that I was using.  I
never did find anything, so I assumed that it didn't exist.

>
> 5) (Only included so I don't look like a _complete_ jerk.  If you get this
> far and you haven't fixed the problem yet, consider this a booby prize.)
> http://divmod.org/trac/browser/trunk/Epsilon/epsilon/spewer.py
> 

I looked at this, and it made my head spin.  I think it is just a touch
too early for me to be looking at things that I don't quite understand.
 :-)  I will take another look at it when I have been amongst the living
a little bit longer.

Thank you for the pointers here.  At the very least, I have new ideas to
google around with (such as looking into "event loops").

As far as programming goes, I have done minor things with it, and web
applications (in PHP).  I have never done GUI programming, or low-level
network programming, or anything like that before, and I tried doing
this project in C++ at first... and then said it wasn't worth it to me.
 So, I'm not very well versed in many of the concepts -- I am literally
used to just writing tiny things (I can do very simple C programs, and
have been known to use PHP for help automating things) to make my life
easier, so this is the first real project that I have tried to work on.

The goal, of course, is to become a better programmer.  But, I digress. :-)

Thanks again!
Mike
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tracing the execution of scripts?

2006-10-27 Thread Michael B. Trausch
Ben Finney wrote:
> Jean-Paul Calderone <[EMAIL PROTECTED]> writes:
> 
>> 1) Write unit tests for your code.  Keep writing unit tests until
>> you have some that _don't pass_.  Then fix your code so that they
>> do.  When you do further development, write the tests first, then
>> implement the code that makes them pass.
> 
> Hear hear.
> 
> Be advised, though, that attempting to apply unit tests to code that
> wasn't designed with testing in mind may very quickly reveal a poor
> design. [0] If you can't easily test pieces of the code independently,
> you probably haven't written those pieces to be loosely coupled and
> well-defined.
>

I will whole-heartedly admit that my code is probably poorly designed.
*shrug*  Though, I *do* try to write everything in such a way as to be
able to easily re-use it later.  When I wrote little things just to help
me sysadmin, I learned that was really key to making my life easier.

Besides, I am lazy... reuse certainly serves my needs there!  :-)

> 
> The moral? Writing unit tests *along with* the functional code will
> result in a design that is loosely coupled, and probably
> better-defined. Also, hopefully, easy to test :-)
> 

I think I have more to learn on the concept of unit-testing.  I have
never seen a group push the idea so hard.  I have read about unit
testing before, and even written tests (in other languages) to test
modules of library code that I put together once, but that was about it.
 I need to, I think, get more "into" the concept, though.  It isn't
something that I am able to just whip out and go "Hey, a widget unit
test!  And it works!" probably because of my own lack of practice.

> 
> [0] I have no idea whether this is the case for the OP. It's a very
> common symptom that arises from people who are first advised to
> introduce tests to their code, though.
> 

It is very likely that it is the case.  I am, by all means, what I could
consider to be a novice programmer when it comes to anything outside of
my little world of PHP.  I can write web applications in PHP until the
cows come home with little to no problem, and I can play with SQL the
same way.  But, I seem to have problems when I step out of that little
box, and so, that tells me that I need to work harder at it.  :-)

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


Re: Tracing the execution of scripts?

2006-10-27 Thread Michael B. Trausch
Stephan Kuhagen wrote:
> "Michael B. Trausch" <"mike$#at^&nospam!%trauschus"> wrote:
> 
>> Basically, is there something that will log every line of Python code
>> executed, in its order of execution, to a text file so that I can see
>> what is (or isn't) happening that I am expecting?
> 
> Python itself can do this for you. A __VERY__ simple approach:
> 
[snip]
> 
> Insert this in you program and you get a trace of every line of Python-Code
> executed in the file trace.txt. You must read the documentation of the
> module inspect and of sys.settrace() to understand, what happens and what
> it means. Additionally, if it should work with threads, you must take care
> that every thread gets its own output file. But as a first step to get a
> trace of execution, this should do it.
> 

I will need to keep this around to look at a little later.  It looks
like it would be something particularly useful when line-tracing by
itself fails.  I am constantly finding myself amazed at Python's
capabilities.

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


Re: PyDev + Eclipse (Was: Re: What's the best IDE?)

2006-10-27 Thread Michael B. Trausch
olive wrote:
> Michael B. Trausch wrote:
> 
>> Yep.  Still does it.
> 
> I'm running PyDev 1.2.4 without completion problem so far.
> 
> Are you up to date ?
> 
> Maybe you should install the latest from scratch.
> 

Yep, I am up to date.  As I said, I am totally confused.

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


Re: PyDev + Eclipse (Was: Re: What's the best IDE?)

2006-11-01 Thread Michael B. Trausch
Éric Daigneault wrote:
> 
> I run the latest pydev on both windows and linux...  The setup is
> excatcly the same (on the eclipse, path setup and all) 
> My windows setup is much better at auto-complete that the linux
> setup...  In linux, other than with self, I seldom get auto complete on
> other classes.  In windows it sometimes can figure out to what class
> belong the instance and propose appropriate choices...
> 
> Caus of my present workload I gave up trying to make it work... 
> E :D.
> 

Yeah, I have given up, too.  I don't really need it, though it would
have been nice to have because I do not (yet) have a second monitor to
attach to my workstation for information-browsing... :-P

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

Using Python within a Python application.

2006-11-02 Thread Michael B. Trausch
Hello, everyone.

I am doing some searching and winding up a little bit confused.  I have
a MUD client that I am writing using Python and wxWidgets, as some of
you may remember.  What I am looking to do now, is add "trigger"
functionality to it.  In essence, the application receives text from the
game, and if it is in any of the trigger definitions, it acts on it by
executing Python code that the user has associated with the action.

So, the question is, what is the safe way to do this?  I have found the
'compile' function, which returns a code object(?) which I would want to
execute using 'exec'.

Here is a hypothetical example:  I want to have a trigger that, when the
game sends the text "That really did HURT!", executes code to instruct
the character to ingest a potion to fix that problem.

In this situation, the user would provide 'That really did HURT!' as the
regular expression, which the game would examine, find that there are no
RE qualifiers in there (e.g., no $, ^, or similar to bind the string to
something else) and turn it into '.*(That really did HURT!).*' to match
it any time the game sends it (unless it breaks in the middle of a
transmission, which I wouldn't be quite sure how to handle, yet).

The associated code, let's say, would be something like:


Tmud.Send('quaff red')


Which would send the text to the game.

Eventually, I would want to support complex things, like handling $1 or
$2 which might be associated with saved portions of the regex, but I
will get there later.

The question is really two-fold:  How can I safely permit the user to
specify Python to be used as part of the game, and how can I create a
module that is used for the user's required functions (e.g., Tmud.Send,
as an example) without requiring each trigger to 'import' something?

I seem to be able to find tons of information on embedding Python in
C/C++/compiled language programs, but not much on safely executing it
within a Python program.  What I really want to do is prevent them from
calling anything that would affect the game client's runtime environment
-- at least from a trigger.  I want to later have some sort of "plug in"
mechanism that people could use to create graphs/charts/meters of
in-game events, but not yet, and that would be separate.

Any ideas?  Thanks in advance!

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


Converting Microsoft Works databases.... *shudder*

2006-11-03 Thread Michael B. Trausch
I was wondering if anyone has had any experience with this.  Someone I
know is trying to move away from Microsoft Works, and I am trying to
look into a solution that would convert their data in a lossless fashion
to a more modern format.  The database has more than 65K rows, so
converting it to be an Excel spreadsheet, would, AFAIK, not be an option.

It would seem that MS Works can export the database as a DBF format
database, though I have not tried it.  Before I get started, I was
wondering if anyone has been through this problem in the past and used
Python to solve the problem.  Knowing nearly nothing about the DBase
family of application software, and database formats, I find myself
feeling like the information out there is, frankly, a bit overwhelming.

Would the recipe specified in the "dbf to csv" thread be useful here for
a file in DBase IV format?  It of course uses the same extension, but I
am not sure if the file semantics are at all similar.  The idea at the
end would be to probably create a database on an small SQL server (like
MySQL) and let the person access their data using ODBC on their Windows
workstation so that they can create form letters and the like.  They do
not have access to MS Office's Access product, nor do they wish to use
OOo Base (and I can't say that I blame them -- it seems to crash far too
often to be considered reliable stuff).

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


Re: Converting Microsoft Works databases.... *shudder*

2006-11-03 Thread Michael B. Trausch
GISDude wrote:
> Mike,
> I totally forgot that MS Works was out there. Haven't used that one in
> about 6 or 7 years. Honestly, your best bet is to convert to .csv or
> some delimited .txt file. Once that is done, all your rows/columns will
> be "nice and neat" .
> Once that is done, (and since your client doesn't have ACCESS, try
> MYSQL or POSTGRESQL(they are open source). They can handle A LOT OF
> DATA, so however big your orginal DB is, you can import it to one of
> these more than capable OS freebie Databases.
> 
> Good luck
>

Yeah; the only thing is that I am going to have to write a solution to
give them "easy" access to their data.  Sometimes, they just want to
look up a row of data, but they don't want to put their data in a
database server -- they want it on their machine so that it is "private"
(FSVO private--it's a Windows box).

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


Re: Converting Microsoft Works databases.... *shudder*

2006-11-03 Thread Michael B. Trausch
Larry Bates wrote:
>
> MS ships ODBC interface to xBase databases in all versions of Windows.
> You don't need Access.  Just create DSN to your exported dBase database
> and MS Word, MS Excel, and any other ODBC aware product can read the
> data.  If the data size is large or if you want to move to server, you
> can do that later.
> 

Oh!  I hadn't realized that Win32 ODBC handled connections to dBase
files.  Learn something new every day... :-)  Thanks!

(I suppose that is something that I would probably know, if I used
Windows...)

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


Lists of lists and tuples, and finding things within them

2006-11-09 Thread Michael B. Trausch




I have a program that keeps some of its data in a list of tuples.  Sometimes, I want to be able to find that data out of the list.  Here is the list in question:

[('password01', 'unk'), ('host', 'dragonstone.org'), ('port', '1234'), ('character01', 'Thessalus')]

For a regular list, I could do something like x.index('host') and find the index of it, but I don't know how to do this for a tuple where the data item isn't known in advance.  For example, I want to get the "host" entry from the list above; but I can only retrieve it if I know what it contains (e.g., x.index(('host', 'dragonstone.org'))).

Is there a better way to do this than a construct similar the following?

for key, value in x:
    if key == 'host':
    print value

Thanks in advance!

    — Mike




--



Michael B. Trausch


[EMAIL PROTECTED]




Phone: (404) 592-5746


Jabber IM: [EMAIL PROTECTED]




Demand Freedom!  Use open and free protocols, standards, and software!





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

Getting externally-facing IP address?

2006-11-10 Thread Michael B. Trausch




Hello,

Every programming example that I have seen thus far shows simple server code and how to bind to a socket--however, every example binds to the localhost address.  What I am wondering is this:  Is there a clean way to get the networked IP address of the machine the code is running on?  For example, my laptop's IP address is 192.168.0.101, and I want to bind a server to that address.  Is there a clean way of doing so that will work, for example, when I move the code to my server (which obviously doesn't have the same IP address)?

Thanks in advance.

    -- Mike




--



Michael B. Trausch


[EMAIL PROTECTED]




Phone: (404) 592-5746


Jabber IM: [EMAIL PROTECTED]




Demand Freedom!  Use open and free protocols, standards, and software!





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

Decimal() instead of float?

2006-11-11 Thread Michael B. Trausch




Is there a way to use Decimal() by default in Python instead of float?  I've no use for the float type, and I have some stuff that would require Decimal(), but it is kind of a pain to try and cast things all over the place all the time.  Float is just way too inexact for me.

I am searching around, and I don't see anything helpful, but I could (as always) be missing something... I tried (rather naïvely) to just do something like:

>>> import decimal
>>> float=Decimal
>>> x=1.1
>>> x
1.1001
>>> 

But, that didn't work (obviously).  It was a shot, anyway.  Are there any ideas, or does anyone have a way around this?  I would prefer to not have to convert incoming floating point numbers to strings and then convert them to Decimal() types every single time that I want to use them (which would be in *every* case).  For example, I have a ZIP code database that can do some processing on its numbers, and the numbers are stored as floating point values (exactly) but Python doesn't get them right; so the Decimal() thing would be needed.  *shrugs*

    Thanks a bunch,
    Mike




--



Michael B. Trausch


[EMAIL PROTECTED]




Phone: (404) 592-5746


Jabber IM: [EMAIL PROTECTED]




Demand Freedom!  Use open and free protocols, standards, and software!





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

Re: Decimal() instead of float?

2006-11-17 Thread Michael B. Trausch
On Wed, 2006-11-15 at 12:48 +0100, Fredrik Lundh wrote:

> Steve Holden wrote:
> 
> >> It /would/ be nice to see Decimal() become the default.  I cannot 
> >> imagine why in an otherwise "human enough" language, math wouldn't be 
> >> included in that without going out of one's way to do it.  :-)
> >>
> > Speed has a lot to do with it. Have you timed some decimal operations 
> > against their floating-point counterparts? It might be possible to build 
> > a version of Python that used decimal instead of floating-point but it 
> > certainly wouldn't be trivial: consider the use of C language libraries 
> > that know nothing of Python's decimal representation.
> 
> judging from the various decimal FAQ:s, I think it's a bit naive to 
> think that using Decimal instead of float would somehow make everything 
> "just work":
> 
> http://www2.hursley.ibm.com/decimal/decifaq.html
> http://effbot.org/pylib/decimal.htm#decimal-faq
> 
> (btw, the OP mentioned in private mail that he wanted to store 
> geographical coordinates in decimal because floats kept messing things 
> up, but given that a 64-bit float can hold enough decimal digits to 
> represent a geographical coordinate with sub-millimeter precision on a 
> global scale, I'm not sure I buy that argument.  I suspect he was just 
> tricked by the usual repr(1.15) != "1.15" issue.  and seriously, under-
> standing the various aspects of floats and decimals is utterly trivial 
> compared to all the nearly-magical things you need to understand to be 
> able to do geographical calculations at a sub-millimeter scale.  heck, 
> even sub-kilometer stuff is pretty hard to get right ;-)


I don't have (so far as I know) a 64-bit float available to me.

Some of the lat/long pairs that I have used seem to come out fine, but
some do not.  Because the mathmatics used with them involve complex
equations when determining distance and the like, any error gets
massively compounded before a final result is evident.  Thus, the
numbers must be exact.  That's why I originally asked if Decimal() can
be used instead.  Since it cannot, that's fine, I will just use
Decimal(), assuming that it supports everything that I will need to do
with the numbers.  If not, then I guess I will have to look at something
that uses GMP.

-- Mike

--
Michael B. Trausch
[EMAIL PROTECTED]
Phone: (404) 592-5746
   Jabber IM: [EMAIL PROTECTED]

Demand Freedom!  Use open and free protocols, standards, and software!
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Decimal() instead of float?

2006-11-17 Thread Michael B. Trausch
On Fri, 2006-11-17 at 21:25 +0100, Fredrik Lundh wrote:

> > Some of the lat/long pairs that I have used seem to come out fine, but 
> > some do not.  Because the mathmatics used with them involve complex 
> > equations when determining distance and the like, any error gets 
> > massively compounded before a final result is evident.
> 
> sorry, but I don't think you have the slightest idea what you're doing, 
> really.
> 


Sure, I do.  Let's say that I want to work with the latitude 33.6907570.
In Python, that number can not be stored exactly without the aid of
decimal.Decimal().

>>> 33.6907570
33.6907568
>>> 

As you can see, it loses accuracy after the 6th decimal place.  That's
not good enough:  I have 8 numbers that need to be exact, and I am only
getting six.  That error will propagate throughout any multiplication or
division problem.  The error compounds itself:

>>> x = 33.6907570
>>> x
33.6907568
>>> x*2
67.3815136
>>>

Now, observe what happens when you compute it exactly:

>>> from decimal import *
>>> xx = Decimal('33.6907570')
>>> xx
Decimal("33.6907570")
>>> xx*2
Decimal("67.3815140")

Now, observe what happens when you compare the differences
pre-multiplication and post-multiplication:

>>> x = Decimal('33.6907570')
>>> y = Decimal('33.6907568')
>>> x - y
Decimal("2E-15")
>>> x = Decimal('67.3815140')
>>> y = Decimal('67.3815136')
>>> x - y
Decimal("4E-15")
>>> 

The discrepancy has carried over and been compounded—and this was a
simple multiplication, not something more advanced.

Now, while 4e-15 is a relatively small difference, it is a difference
that will continue to grow due to the inexact nature of the numbers.
This is proof enough that when exact precision is needed, the regular
floating point numbers should not be used.  *I* need exact numbers—plain
and simple.  Those are the requirements for the project I am working on,
and thus I must adhere to them—and they are non-negotiable, which is why
I had opened this thread to begin with.  I wanted to know if there was a
way to simply switch the default mechanism, that's all.  Quite simply,
we're talking about a project where the requirements are absolutely zero
tolerance for error—and it is clearly evident that Python cannot use a
float to store a simple latitude number without causing some error in
the precision.  And it doesn't take a genius to realize that when you
introduce an error—even a minuscule one—into a long sequence of
equations, and those equations involve multiplication and division, the
error becomes compounded and unpredictable.

An example:

>>> 1.1
1.1001
>>> 1.1+0.1
1.2002
>>> 1.2
1.2
>>> 1.1*10
11.001
>>> 

This does not make any sense at all.  Why is 1.1 == 1.1 and some change,
and 1.1 + 0.1 is off, but 1.2 is not off on its own?  Or, for that
matter, why doesn't the default float type recognize that 1.1*10 =
11 without any more floating point?  It is a whole number.

Perhaps you should not make assumptions; I am sure that you have heard
what they do at some point before.  While *some* of the error doesn't
propagate as expected (which is actually a problem in itself—equations
no longer make sense if they are not mathematically balanced!) some
does.  It is unpredictable and can't be tolerated when the numbers must
come out exactly.

— Mike

--
Michael B. Trausch
[EMAIL PROTECTED]
Phone: (404) 592-5746
   Jabber IM: [EMAIL PROTECTED]

Demand Freedom!  Use open and free protocols, standards, and software!
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: How a script can know if it has been called with the -i command line option?

2006-12-22 Thread Michael B. Trausch
Peter Wang wrote:
> Michele Simionato wrote:
>> The subject says it all, I would like a script to act differently when
>> called as
>> $ python script.py and when called as $ python -i script.py. I looked
>> at the sys module
>> but I don't see a way to retrieve the command line flags, where should
>> I look?
> 
> I realize this is quite a hack, but the entire command line is
> preserved in the process's entry in the OS's  process table.  if you do
> "ps -ax" you will see that the interpreter was invoked with -i.  I
> didn't test this under windows, but it works on Mac and Linux.
> 

There is a set of utilities that have UNIX-like ps behavior, but, as is 
typical for Windows, they don't work the way their UNIX and UNIX-like 
counterparts do.  Does 'ps' work from within Cygwin, and if so, would 
redistributing that be an option?

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


UTF-8 output problems

2007-03-09 Thread Michael B. Trausch
I am having a slight problem with UTF-8 output with Python.  I have the
following program:

x = 0

while x < 0x4000:
print u"This is Unicode code point %d (0x%x): %s" % (x, x,
unichr(x))
x += 1

This program works perfectly when run directly:

[EMAIL PROTECTED]:~/tmp$ python test.py
This is Unicode code point 0 (0x0):
This is Unicode code point 1 (0x1):
This is Unicode code point 2 (0x2):
This is Unicode code point 3 (0x3):
This is Unicode code point 4 (0x4):
This is Unicode code point 5 (0x5):
This is Unicode code point 6 (0x6):
This is Unicode code point 7 (0x7):
This is Unicode code point 8 (0x8):
This is Unicode code point 9 (0x9):
This is Unicode code point 10 (0xa):
(... continued)

However, when I attempt to redirect the output to a file:

[EMAIL PROTECTED]:~/tmp$ python test.py >f
Traceback (most recent call last):
  File "test.py", line 6, in 
print u"This is Unicode code point %d (0x%x): %s" % (x, x,
unichr(x))
UnicodeEncodeError: 'ascii' codec can't encode character u'\x80' in
position 39: ordinal not in range(128)

This is slightly confusing to me.  The output goes all the way to the
end of the program when it is not redirected.  Why is Python treating
the situation differently when the output is redirected?  This failure
occurs for all redirection, by the way: >, >>, 1>2, pipes, and so forth.

Any ideas?

— Mike

--
Michael B. Trausch
[EMAIL PROTECTED]
Phone: (404) 592-5746
  Jabber IM:
[EMAIL PROTECTED]
  [EMAIL PROTECTED]
Demand Freedom!  Use open and free protocols, standards, and software!


signature.asc
Description: This is a digitally signed message part
-- 
http://mail.python.org/mailman/listinfo/python-list

Character set woes with binary data

2007-04-01 Thread Michael B. Trausch
I am attempting to piece together a Python client for Fotobilder, the
picture management server on Livejournal.

The protocol calls for binary data to be transmitted, and I cannot seem
to be able to do it, because I get this error:

>>> sb.UploadSinglePicture('/home/mbt/IMG_2618.JPG')
Traceback (most recent call last):
  File "", line 1, in 
  File "scrapbook.py", line 181, in UploadSinglePicture
{Request['UploadPic.Meta.Filename']: pic_mem})
  File "scrapbook.py", line 237, in ComposeMIME
return(self.EncodeMIME(fields, files))
  File "scrapbook.py", line 226, in EncodeMIME
body = eol.join(L)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0:
ordinal not in range(128)
>>> 

When putting the MIME segments (listed line-by-line in a Python list)
together to transmit them.  The files are typically JPG or some other
binary format, and as best as I understand the protocol, the binary data
needs to be transmitted directly (this is evidenced by looking at the
tcp-stream of an existing client for uploading files).

It seems that Python thinks it knows better than I do, though.  I want
to send this binary data straightaway to the server.  :-)

This is a hex dump of what one file looks like being uploaded to the
server (partial; the file is 3.8 MB):

01CB  ff d8 ff e1 3b fc 45 78  69 66 00 00 49 49 2a 00 ;.Ex
if..II*.
01DB  08 00 00 00 09 00 0f 01  02 00 10 00 00 00 7a
00  ..z.
01EB  00 00 10 01 02 00 10 00  00 00 aa 00 00 00 12
01  
01FB  03 00 01 00 00 00 01 00  00 00 1a 01 05 00 01
00  
020B  00 00 da 00 00 00 1b 01  05 00 01 00 00 00 e2
00  
021B  00 00 28 01 03 00 01 00  00 00 02 00 00 00 31
01 ..(. ..1.
022B  02 00 1e 00 00 00 ea 00  00 00 13 02 03 00 01
00  
023B  00 00 02 00 00 00 69 87  04 00 01 00 00 00 54
01 ..i. ..T.
024B  00 00 ac 12 00 00 48 65  77 6c 65 74 74 2d 50 61 ..He
wlett-Pa
025B  63 6b 61 72 64 00 00 00  00 00 00 00 00 00 00 00
ckard... 
026B  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00
00  
027B  00 00 00 00 00 00 50 68  6f 74 6f 73 6d 61 72 74 ..Ph
otosmart
028B  20 4d 35 32 35 00 00 00  00 00 00 00 00 00 00 00
M525... 
029B  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00
00  
02AB  00 00 00 00 00 00 e6 00  00 00 01 00 00 00 e6
00  
02BB  00 00 01 00 00 00 56 65  72 73 69 6f 6e 20 31 2e ..Ve
rsion 1.
02CB  34 31 30 30 2c 53 4e 3a  43 4e 36 34 31 44 33 31 4100,SN:
CN641D31
02DB  4a 35 53 00 00 00 00 00  00 00 00 00 00 00 00 00
J5S. 
02EB  00 00 00 00 00 00 ff ff  ff ff ff ff ff ff ff
ff  
02FB  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff
ff  
030B  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff
ff  
031B  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff
ff  
032B  27 00 9a 82 05 00 01 00  00 00 96 08 00 00 9d 82
'... 

Is there any way to tell Python to ignore the situation and treat the
entire thing as simply a stream of bytes?  I cannot seem to find one,
though I have found a great many posts on this mailing list regarding
issues in the past.  It doesn't look like translating the file to base64
is an option for me.

— Mike

--
Michael B. Trausch
[EMAIL PROTECTED]
Phone: (404) 592-5746
  Jabber IM:
[EMAIL PROTECTED]
  [EMAIL PROTECTED]
Demand Freedom!  Use open and free protocols, standards, and software!


signature.asc
Description: This is a digitally signed message part
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Character set woes with binary data

2007-04-01 Thread Michael B. Trausch
On Sun, 2007-04-01 at 06:09 -0300, Gabriel Genellina wrote: 

> > When putting the MIME segments (listed line-by-line in a Python list)
> > together to transmit them.  The files are typically JPG or some other
> > binary format, and as best as I understand the protocol, the binary data
> > needs to be transmitted directly (this is evidenced by looking at the
> > tcp-stream of an existing client for uploading files).
> 
> But I think your problem has nothing to do with MIME: you are mixing  
> unicode and string objects; from your traceback, either the "L" list or  
> "eol" contain unicode objects that can't be represented as ASCII strings.
> 


I never said it did.  It just happens to be the context with which I am
working.  I said I wanted to concatenate materials without regard for
the character set.  I am mixing binary data with ASCII and Unicode, for
sure, but I should be able to do this.

The current source can be found at
http://fd0man.theunixplace.com/scrapbook.py which is the version that I
am having the problem with.


> > It seems that Python thinks it knows better than I do, though.  I want
> > to send this binary data straightaway to the server.  :-)
> 
> You don't appear to be using the standard email package (which includes  
> MIME support) so don't blame Python...
> 


I am not saying anything about Python's standard library.  Furthermore,
I am not using MIME e-mail.  The MIME component that I am using, which
should be ideal for me, builds the message just fine—when not using a
binary component.  I am looking for how to tell Python to combine these
objects as nothing more than a stream of bytes, without regard for what
is inside the bytes.  That is what I was asking.  You did not tell me
how to do that, or if that is even possible, so why flame me?  I am not
saying "Python is bad, evil!" and blaming it for my ignorance, but what
I am asking for is how to accomplish what I am attempting to accomplish.
The MIME component is a (slightly modified) version of the recipe
provided from the ASPN Python Cookbook.

In short:  How do I create a string that contains raw binary content
without Python caring?  Is that possible?

Thanks,
Mike


> -- 
> Gabriel Genellina
> 


--
Michael B. Trausch
[EMAIL PROTECTED]
Phone: (404) 592-5746
  Jabber IM:
[EMAIL PROTECTED]
  [EMAIL PROTECTED]
Demand Freedom!  Use open and free protocols, standards, and software!


signature.asc
Description: This is a digitally signed message part
-- 
http://mail.python.org/mailman/listinfo/python-list