Mega Newbie Questions: Probably FAQs

2006-08-14 Thread Zeph
I'm pretty well of a mind to pick up Python. I like it because it seems 
to have a fair degree of functionality and is accessible to someone 
without a PhD in computer sciences. This is my second day of 
investigation, and I'm astounded by the huge ecosystem that surrounds 
it. I have a number of questions that probably should be on a FAQ, but I 
haven't found them. I'll explain my goals and needs, perhaps someone 
here will have some recommendations

1) I want to write high-level apps that are db connected, networkable 
and cross-platform: Linux, Mac OSX, Windows. I know there are apps that 
can convert to Linux or Windows as stand-alone executables, is there 
also one that will permit me to convert to MacOSX?

1b) Are these executable completely free from the need of the average 
user needing to install Python. Basically, I want to write and sell 
"compiled" apps.

2) I want a real and native GUI. wxPython or PyQT? My concerns are about 
cross-platform and responsiveness of GUI. I suspect that this will be 
one of the gravest issues for the long run.

3) Can someone recommend a good framework that will enable me to keep 
things well sorted out, and easy to maintain as my apps grow? (I'm 
considering MVC, but have no idea how to apply it until I've gone beyond 
"Hello World").

4) There are a lot of books and tutorials out there, but they are of the 
proof-of-concept type. Specifically, a tutorial might teach me Hello 
World, but not really care about the framework, because it's a very 
simple item, and the point is simply to get me coding. I'd like to start 
off with an established, tested and reputable system whose habits I can 
ingrain from day one, rather than figure it out later. Can someone 
recommend a good book, or your favourite tutorials? Perhaps even one 
that assumes MVC as the framework?

5) Following the above, is there a framework that assumes tcp/ip udp 
networking, database connectivity? My first app will be in large part a 
networkable database type app where two or more users can share the same 
file concurrently.

6) Since I've been a web-developer for a long time (over 10 years), I 
never properly learned OOP. Recommended tutorials?

7) I'm developing on WinXP and for the IDE, I'm considering 
theKompany.com's BlackAdder, Komodo or Eclipse. Any very strong 
negatives in regards to either of these?

8) Can anyone speak to the point, or point out a useful comparison 
between Python and RealBasic?

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


Re: Mega Newbie Questions: Probably FAQs

2006-08-14 Thread Zeph
ajaksu wrote:
> Hoping this helps more than confuses,

Thanks, these were the sort of answers I was looking for. I've 
programmed in Basic, AppleScript, Pascal and Usertalk (Userland 
Frontier), I've got a sense for development, it's just been a very, very 
long time ago.

I do intend to start small and build up, but I want to front load my 
learning curve, usually makes the other side of the curve more productive.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Mega Newbie Questions: Probably FAQs

2006-08-14 Thread Zeph
ajaksu wrote:
> Zeph wrote:
And I'd research a bit about decompiling those executables,
> might be easier (or harder,  in my case) than you thought :)

Are you saying that generally python code is insecure? It hadn't 
occurred to me, but I want to play in a fairly competitive field, and 
I'd hate to have a competitor rip my app.

> Framework... MVC... not my area, sorry.

I think a better word might have been "methodology", for example, as a 
Coldfusion developer, I enjoy using Fusebox.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Mega Newbie Questions: Probably FAQs

2006-08-14 Thread Zeph

Zeph wrote:
>> 3) Can someone recommend a good framework that will enable me to keep 
>> things well sorted out, and easy to maintain as my apps grow? (I'm 
>> considering MVC, but have no idea how to apply it until I've gone 
>> beyond "Hello World").

Yu-Xi Lim wrote:
> Framework for what kind of apps? Web, native GUI, client-server, etc?
> MVC is an abstract architecture rather than a specific implementation.
> Even so, many implementations rarely employ a purely MVC design.

Native GUI with some client-server abilities. Basically, it's a 
database-inventory sort of thing with some pretty intense reporting. 
Call it a productivity app--no need for intense graphics or massive 
computation. Fundamentally, what I want is to be able to distribute a 
"regular app", mainly for the Windows market, but I also want to offer 
it to the Mac and Linux crowd--on one code base if possible.

I have on a number of occasions downloaded apps that required that 
Visual Basic, or .Net or whatever runtimes be installed. I've never 
liked or trusted these kinds of apps. Regardless of the quality that the 
particular thing may have had, I didn't trust it and didn't like all of 
the extra clutter that went along with it. This is why I'd prefer to 
deliver some sort of stand alone solution--or at least something that 
appears as such. Fundamentally, I want to put out a solid, slick and 
professional product. Is Python still a good choice for me?

Back to the question: When I speak of framework, maybe I should have 
used the term "methodology". I have excellent methods for coding my 
web-apps (I like Fusebox) but not having created anything significant in 
another language from scratch for over 10 years, I wouldn't know how to 
start organizing my stuff so that it's long-term maintainable.

> The size of the Python community is huge compared to RealBasic. And
> you'll benefit from that alone by better answers to your questions,
> better documentation, and better 3rd party libraries.

Excellent points.

> Side note: You seem like you've researched a bit, but unfortunately been
> affected by the swirl of buzzwords. While there are usually valid
> reasons for particular technologies to have so much hype behind them,
> you should not neglect the alternatives. They may be the answer you seek.

Yes. That's the problem with being a newb: you don't know what you don't 
know, then when you do, it's obvious. I'm still seeing only the surface.

One question that does come to my mind is that of the notion of 
decompiling or reverse engineering. Based on a comment someone made 
earlier, is this a significant concern that I should have, if I want to 
ship commercial software?

The stage I'm at right now is that I'm on the fence between REALbasic 
and Python.

Here's how I see it, relevant to my situation:


REALbasic
Pros: A fairly rich system, excellent GUI, spits out a binary executable 
for Win, Mac and Linux. One code base. Well documented, ever evolving. 
Relatively reasonably priced for commercial purposes.

Cons: Closed source (what if they're bought out?) I'm not sure that I 
can trust my investment of time to last 10 years. The language and IDE 
is a tad strange to me. It has the word "Basic" (read: cheap, 
half-assed, not-a-real-app) in it, which is not a particularly good term 
to use in a pitch.

Unknown: Learning curve? Long-term value? Level of support?

Python
Pros: Free. Open source. Deep. Flexible. Rich community and third party 
stuff. Well documented.

Cons: Interpreted.

Unknown: Secure (meaning not easily reverse engineered) code? Performance?


Further thoughts?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to tell if you're running on windows?

2009-12-04 Thread zeph
On Dec 4, 10:46 am, Roy Smith  wrote:
> I'm using 2.5.1.  How can I tell if I'm running on windows?  The
> obvious answer, platform.system(), gets complicated.  On the python
> that comes with cygwin, it returns 'CYGWIN_NT-5.2-WOW64', but I've got
> a native windows build of python where it returns 'Microsoft'.
>
> The real problem I'm trying to solve is whether to build a LIBPATH
> environment variable with ';' or ':' delimiting the entries.  On the
> cygwin build, os.pathsep returns ':', which isn't really correct.  If
> you use that, you end up building paths that look like c:foo:c:bar.
> It should be c:foo;c:bar

The Cygwin shell uses what appears to be its own pseudo-filesystem. If
you open your Cygwin shell window and type echo $PATH you will see
completely different results from the Windows command shell's PATH env
variable, and you'll see the path sep is indeed ':'.

Cygwin also seems to put drive mount points in /cygdrive/ so you will
have for example "/cygdrive/c/foo:/cygdrive/c/bar" instead of "C:
\foo;C:\bar".

For python *outside* of Cygwin, on Windows, I assume os.path.pathsep
is ';'.

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


Re: Difference between mutex.mutex and threading.Lock

2009-12-04 Thread zeph
The mutex class (and module) should not be used, since it is, as you
said, deprecated for 3.0. Like the docs say, it "does not require (or
imply) threading or multi-tasking, though it could be useful for those
purposes."  The mutex class' lock() method takes a function and args
and if the mutex is unlocked, calls the function with args
immediately, or if locked, adds to a queue and waits for it to be
unlocked

The threading.Lock object is a lock shared between threads.  For
example, if you have two threads (thread1 and thread2) and thread1
does lock.acquire() and thread 2 calls lock.acquire(), thread2 will
block until thread1 calls lock.release(), then thread2 will get a
chance to run its critical code section, then call lock.release().

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


Re: How to timeout when waiting for raw_input from user ?

2009-12-05 Thread zeph
Here's what I came up with, though it only asks once question then
quits depending on the answer or lack thereof.  And while, yes, you
can't interrupt a raw_input call from a timer, providing for a blank
line (user hitting enter) is a way around it:

import threading import Timer
from random import randrange
import sys

def multiply_game():
  a = randrange(1,10)
  b = randrange(1,10)
  answer = raw_input('what is %s * %s?: ' % (a,b))
  if not answer:
return
  timer.cancel()
  if str(answer) == str(a * b):
print 'right! :D'
  else:
print 'wrong :('

def tooslow():
  print "\ntoo slow :(\nHit ENTER to quit"

timer = Timer(30, tooslow)  # 30 seconds
timer.start()
multiply_game()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Organization of GUIs

2009-12-05 Thread zeph
I highly recommend reading the Cocoa documentation, which has volumes
on all sorts of things like this.  Here's a link that talks about
views in that context, and should give you more ideas about well-
designed GUI layouts: http://bit.ly/6b8PYh
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is the significance of after() in this code?

2009-12-06 Thread zeph
On Dec 6, 8:46 pm, Benjamin Kaplan  wrote:
> On Sun, Dec 6, 2009 at 10:29 PM, W. eWatson  wrote:
> > See Subject.
> >    def StackImages(self):
> >        self.Upload("P")
> >        self.after_id = self.master.after(1,self.GetFrameOne)
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
> I think this is close to winning an award for "least information
> provided". How are we supposed to know with the information you gave
> us? We don't know what package you're using, what type anything is, or
> even the purpose of that method. Try putting this line in there
> somewhere
> print type(self.master)
>
> and then open up the interactive interpreter, import whatever you need and do
> help(.after)


True, though by *context* the after method looks like it takes a time
(probably in milliseconds, given its size), and a method, and calls
the method after that amount of time, and returning some process/
thread id to self.after_id.  Though if that's right, we still don't
know if its synchronous or not, if its calling it in a new thread or a
new process, etc etc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: test if an input string starts with a python expression

2009-12-07 Thread zeph
It sort of sounds like you want a templating system:
http://wiki.python.org/moin/Templating
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: switch

2009-12-08 Thread zeph
>
> Even better (well, shorter!):
> options = {"a" : do_a, "b",do_b, "c", do_c}
> options.get(option, do_default)()
>

You can also make it something callable like so, which is a little
more compact if you need to reuse it a lot:

>>> def do_a(x): print "a:", x
...
>>> def do_b(x): print "b:", x
...
>>> def do_c(x): print "c:", x
...
>>> do_something = {"a":do_a, "b":do_b, "c": do_c}.get
>>> do_something('a')(4)
a: 4
>>> do_something('c')(5)
c: 5
>>> do_something

>>> do_something('d')
>>> do_something('d')(5)
Traceback (most recent call last):
  File "", line 1, in 
TypeError: 'NoneType' object is not callable
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I Block Events in wxPython

2009-12-09 Thread zeph
The wxPython wiki actually has a page on dealing with long running
tasks called from event handlers called (surprise surprise):
http://wiki.wxpython.org/LongRunningTasks

Hint: the second to last example on that page has the clearest example
- using a worker thread object to do your DoEfficiency() function.

I also don't think you want to disable so many event handlers, do
you?  Nothing will respond to inputs as long as that process is
running (assuming you aren't running it in another thread.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Perl to Python conversion

2009-12-09 Thread zeph
Python and Perl often have different design idioms - learning to write
*well* in a language involves understanding those idioms, and being
able to translate between languages involves understanding the source
language well enough to understand the intent of the program's code
(even if its poorly written), and understanding the target language
well enough to translate the intent into a design fitting the
language.

Perl and Python have enough syntactic similarities that you could, if
you wanted, just translate the program verbatim.

Overall, I would recommend adding your imperial->metric functionality
to the Perl code for now, and on your free time work on translating to
Python, so you don't feel rushed to get it finished.  You will
probably come to understand the Perl code better after having worked
with it and been involved in a hands-on way with it.  Likewise, you
will become even more familiar with it and with Python as you learn
how to translate the application.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Moving from PHP to Python. Is it Possible

2009-12-11 Thread zeph
Hi Sancar,

1) PHP does some really nasty things in how it treats globals, and you
will have to break yourself of those sorts of habits -- Python offers
much cleaner alternatives, like grouping similar functionality into
modules which can be imported; the import functionality in python is
pretty flexible.
Python won't pack a ton of garbage into a giant, global
'dictionary' (what python calls associative arrays).  There are
modules (bundled of code) which you can import to handle your needs.

2) Check out the traceback[1] module for retrieving the traceback info
for logging to a file, and cgitb[2] modules for printing the traceback
as HTML to your browser.

3) http://docs.python.org/ is a great place to start - it has a lot of
well written and generally thorough documentation with examples

4) It's better to collect all your eventual output into a string that
you print - there are examples at [3]. You can import from other
modules as needed (even conditionally), grow your string for output,
then finally print it like (this example was adapted from one found on
[3]):

output =  ''
output += 'My Page'
output += ''
output += 'Powers of two\n'
for n in range(1,11):
  output += ''+str(2**n)+''

output += ''
print output


You can copy-paste this right into your Python interactive shell to
see the output. Note: += is inline string concatenation.


5) You can get form state from the cgi module[4] and FormStorage
object, and you can get server environment data from the os.environ[5]
dictionary;

Good luck and keep on learning! :-)

- zeph


References:
1: http://docs.python.org/library/traceback.html
2: http://docs.python.org/library/cgitb.html
3: http://gnosis.cx/publish/programming/feature_5min_python.html
4: http://docs.python.org/library/cgi.html
5: http://docs.python.org/library/os.html#process-parameters
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Moving from PHP to Python. Is it Possible

2009-12-11 Thread zeph
On Dec 11, 8:58 am, MRAB  wrote:
> output = ['']
> output.append('My Page')
> output.append('')
> output.append('Powers of two\n')
> for n in range(1, 11):
>      output.append('%s' % (2 ** n))
>
> output.append('')
> print ''.join(output)

Agreed (I might join on '\n' though), I was just trying to introduce
as few new concepts as possible :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: parallelpython 1.5.7 crash

2009-12-12 Thread zeph
I looked in the browsable svn repo for parallel python at
http://parallelpython.googlecode.com/svn/trunk/

1) OverflowError: long int too large to convert to int

This is a bug in their code (comments are mine) in pytransport.py:

size_packed = self.r.read(struct.calcsize("!Q"))  # reads in 8-
character string
msg_len = struct.unpack("!Q", size_packed)[0] # unpacks to a long
value, e.g. "12345678" -> 3544952156018063160L
msg = self.r.read(msg_len)#
3544952156018063160L is too long for file.read, which I presume must
be able to cast as an int

As an example:
>>> sys.stdin.read(3544952156018063160L)
Traceback (most recent call last):
  File "", line 1, in 
OverflowError: long int too large to convert to int



2) UnboundLocalError: local variable 'sresult' referenced before
assignment

This is another bug in their code. This is an error in pp.py (again,
comments are mine, some code omitted for brevity):

try:
  # ...snip...
  sresult = worker.t.receive()   # sets sresult
except:
  if self.__exiting:
return
  else:
# at this point, __run doesn't return, but sresult was not defined
since the
# execution was unwound because, presumable, the first fatal you
got, the OverflowError
sys.excepthook(*sys.exc_info())
# ...snip...
job.finalize(sresult)  # UnboundLocalError here from missing sresult


You can submit these as a bug report to the author if you want - feel
free to copy-paste or link to this post :-)

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