Re: [Tutor] Python 2.7.1 interpreter passing function pointer as function argument and Shedskin 0.7

2010-12-28 Thread Stefan Behnel

Frank Chang, 28.12.2010 22:35:

Good afternoon. I want to thank everyone who helped me fix the global
name 'levinshtein_automata' is not defined error.
When I run the Shedskin 0.7 Python to C+++ compiler on the
same python program, I receive the error message * Error *
automata_test.py:148 : unbound identifier 'lookup_func'.


ShedSkin is very restrictive compared to CPython. It requires static types 
for variables and it doesn't support all Python features.


Is there a reason you want to use ShedSkin for your program?

Stefan

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python 2.7.1 interpreter passing function pointer as function argument and Shedskin 0.7

2010-12-28 Thread bob gailer

On 12/28/2010 4:35 PM, Frank Chang wrote:
   Good afternoon. I want to thank everyone who helped me fix the 
global name 'levinshtein_automata' is not defined error.
   When I run the Shedskin 0.7 Python to C+++ compiler on the 
same python program, I receive the error message * Error * 
automata_test.py:148 : unbound identifier 'lookup_func'. lookup_func 
is a python function pointer passed as an argument to a python function.


I'd like to help

Please post the entire traceback.

Fix the indentation. I have to make too many assumptions with the 
indentation messed up.


Let's refine our terminology. Python does not pass pointers, it passes 
objects.


m is not a function. It is a callable class instance.

  I have marked lines 148,161,172 and 174 in the python program 
automata_test.py shown below. The shedskin tutorial says  the latest 
version of the Shedskin 0.7 Python to C++ compiler does not support 
overloading __iter__ and __call__.  I was wondering if anyone could 
suggest a python workaround to this error message as I am new to 
python. Thank you.

# automata_test.py
 import bisect
import random
class NFA(object):
 EPSILON = object()
 ANY = object()
 def __init__(self, start_state):
 self.transitions = {}
  self.final_states = set()
  self._start_state = start_state
 @property
 def start_state(self):
return frozenset(self._expand(set([self._start_state])))
 def add_transition(self, src, input, dest):
self.transitions.setdefault(src, {}).setdefault(input, 
set()).add(dest)

 def add_final_state(self, state):
self.final_states.add(state)
 def is_final(self, states):
return self.final_states.intersection(states)
 def _expand(self, states):
frontier = set(states)
while frontier:
   state = frontier.pop()
   new_states = self.transitions.get(state, {}).get(NFA.EPSILON, 
set()).difference(states)

  frontier.update(new_states)
   states.update(new_states)
return states
 def next_state(self, states, input):
dest_states = set()
for state in states:
  state_transitions = self.transitions.get(state, {})
  dest_states.update(state_transitions.get(input, []))
  dest_states.update(state_transitions.get(NFA.ANY, []))
return frozenset(self._expand(dest_states))
 def get_inputs(self, states):
inputs = set()
for state in states:
   inputs.update(self.transitions.get(state, {}).keys())
return inputs
 def to_dfa(self):
   dfa = DFA(self.start_state)
   frontier = [self.start_state]
   seen = set()
   while frontier:
  current = frontier.pop()
  inputs = self.get_inputs(current)
  for input in inputs:
if input == NFA.EPSILON: continue
   new_state = self.next_state(current, input)
   if new_state not in seen:
  frontier.append(new_state)
  seen.add(new_state)
  if self.is_final(new_state):
dfa.add_final_state(new_state)
   if input == NFA.ANY:
  dfa.set_default_transition(current, new_state)
   else:
  dfa.add_transition(current, input, new_state)
   return dfa


class DFA(object):
def __init__(self, start_state):
  self.start_state = start_state
  self.transitions = {}
  self.defaults = {}
  self.final_states = set()
def add_transition(self, src, input, dest):
  self.transitions.setdefault(src, {})[input] = dest
def set_default_transition(self, src, dest):
  self.defaults[src] = dest
def add_final_state(self, state):
  self.final_states.add(state)
def is_final(self, state):
  return state in self.final_states
def next_state(self, src, input):
  state_transitions = self.transitions.get(src, {})
  return state_transitions.get(input, self.defaults.get(src, None))
def next_valid_string(self, input):
   state = self.start_state
   stack = []
  # Evaluate the DFA as far as possible
   print state
   for i, x in enumerate(input):
  print "%s" % input
  print 'e'
  stack.append((input[:i], state, x))
  state = self.next_state(state, x)
  if not state: break
else:
  stack.append((input[:i+1], state, None))

if self.is_final(state):
 # Input word is already valid
 return input
  # Perform a 'wall following' search for the 
lexicographically smallest

  # accepting state.
 while stack:
 path, state, x = stack.pop()
 x = self.find_next_edge(state, x)
 #print 'x'
if x:
  path += x
state = self.next_state(state, x)
  if self.is_final(state):
 print 'p'
 return path
 stack.append((path, state, None))
 print 'v'
 return None
def find_next_edge(self, s, x):
if x is None:
x = '\0'
else:
x = chr(ord(x) + 1)
state_transitions = self.transitions.get(s, {})
 if x in state_transitions or s in self.defaults:
   return x
la

Re: [Tutor] Java Virtual Machine Launcher Question

2010-12-28 Thread Walter Prins
I'm guessing this question has something to do with this:
http://isatab.sourceforge.net/validator.html

Which appears to be some sort of Java application that validates "isatab"
files, which appear to be related to mentioned magetab files.

I'm further guessing that you thought a .jar file (A Java program archive)
would be openable by WinRAR, since it can open .rar files?  If so, they are
utterly different things.  If not, then apologies and please excuse my
incorrect inferrence.

It's unclear to me how this question relates to Python though?  Are you
trying to implement reading/writing/validation of isatab files in Python or
something?

Many thanks,

Walter
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Opening and closing SQLite db

2010-12-28 Thread David Hutto
So in the end it boils down to:

What you want the db to hold?

When do you need the db to hold it?

And...

When and where is it necessary to access it by the user?

Ah! Not an algorithm.

Many paths, same destination...grasshoppa.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Opening and closing SQLite db

2010-12-28 Thread David Hutto
On Tue, Dec 28, 2010 at 9:18 PM, David Hutto  wrote:
> But in the case you need the db constantly open(such as tracking
> something, where you update the db

This assumes you don't connect directly to, but update from, for data
analysis, not real time tracking.

through some other offsite db),
> then just committing the current would be suggestible(in my opinion),
> and keeping the update live to check periodically for changes in the
> timestamps of data from the updatable source.
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Opening and closing SQLite db

2010-12-28 Thread David Hutto
But in the case you need the db constantly open(such as tracking
something, where you update the db through some other offsite db),
then just committing the current would be suggestible(in my opinion),
and keeping the update live to check periodically for changes in the
timestamps of data from the updatable source.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] blank space after a number

2010-12-28 Thread bob gailer

On 12/28/2010 8:09 PM, bob gailer wrote:

Now that I understand what you want -

for b in range(120):
 print '%0*i' % (max(2,int(math.log10(b))), b)


Sorry forgot to add
import math

--
Bob Gailer
919-636-4239
Chapel Hill NC

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python 2.7.1 interpreter passing function pointer as function argument and Shedskin 0.7

2010-12-28 Thread Alan Gauld


"Frank Chang"  wrote


  When I run the Shedskin 0.7 Python to C+++ compiler on the
same python program, I receive the error message * Error *
automata_test.py:148 : unbound identifier 'lookup_func'. lookup_func 
is a

python function pointer passed as an argument to a python function.
 I have marked lines 148,161,172 and 174 in the python program
automata_test.py shown below. The shedskin tutorial says  the latest 
version
of the Shedskin 0.7 Python to C++ compiler does not support 
overloading

__iter__ and __call__.



These sound like issues with shedskin rather than Python, you
will probably get better support on their forum/newsggroup/list.

You may also find other compilers deal with your particular needs
better - cython for example.

But finally, remember that Python is not C++. If you really
need C++ use C++. The compilers are clever and can save a lot of
effort, but Python is primarily an dynamic interpreted language and
a lot of its more advanced idioms do not translate easily to 
statically

compiled code.

HTH,



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] blank space after a number

2010-12-28 Thread Alan Gauld

"Enih Gilead"  wrote


a, b = 0, 1
while b < 10:
  print '%i%i' % (a,b) + ',',
  b = b+1


If you are using string formatting it's best to get the format
string to do as much of the work as possible. In this case
forget about 'a' and just insert the zero into the string, and
similarly don't add a comma and space, just put it in the string
And for a fixed number of iterations a for loop is usually
preferable:

for b in range(1,10):
   print "%02d, " % b


Does the same job.

'''
01, 02, 03, 04, 05, 06, 07, 08, 09, '''




while b < 100:
  print '%i' % (b) + ',',
  b = b+1



And exactly the same code with the limit increased

for b in range(1,101):   #NB 101 to get the 100 - your while loop goes 
to 99...

   print "%02d, " % b


'''
01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12, 13, 14, 15, 16, 17, 
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 
35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 
69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 
86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100 '''


The %02d says print the number as two characters, padding with zeros
as needed.

HTH,


--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] blank space after a number

2010-12-28 Thread bob gailer

Now that I understand what you want -

for b in range(120):
 print '%0*i' % (max(2,int(math.log10(b))), b)

--
Bob Gailer
919-636-4239
Chapel Hill NC

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] blank space after a number

2010-12-28 Thread Noah Hall
I'll just add there's a better way to do both of the examples you've done
there -


> > a, b = 0, 1
> > while b < 10:
> >print '%i%i' % (a,b) + ',',
> >b = b+1


An easier way of doing this is to instead do the following, including the a
(although not needed, as simply using 0 would work) -

a, b = 0, 1
while b <10:

print '%i%i,' % (a,b),
b += 1

> while b < 100:
> > print '%i' % (b) + ',',
> > b = b+1
>

while b < 100:

print '%i,' % (b),
b += 1

Or, using generators and a *for *loop (which is more suited to the task than
a *while *loop):

def stringify(x):

if x < 10:

return '0' + str(x)

else:

return str(x)

print ','.join(stringify(x) for x in xrange(1,101))
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] blank space after a number

2010-12-28 Thread Enih Gilead

Thanks a lot,
Hugo Yoshi!

As a beginner in Python, I do my best to satisfy my curiosity about some 
features in the language; and, this one was the most difficult among my 
"projects"!  :c)


Best regards,
Enih Gil'ead



# Formatting numbers from '01,' to '100'
# Many thanks to Bob Gailer and to Hugo Yoshi

a, b = 0, 1
while b < 10:
  print '%i%i' % (a,b) + ',',
  b = b+1
  # what results in:
'''
01, 02, 03, 04, 05, 06, 07, 08, 09, '''

while b < 100:
  print '%i' % (b) + ',',
  b = b+1
  # what results in:
'''
01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12, 13, 14, 15, 16, 17, 18, 
19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 
37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 
55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 
73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 
91, 92, 93, 94, 95, 96, 97, 98, 99, 100 '''


print 100






On 12/28/2010 05:31 PM, Hugo Arts wrote:

On Tue, Dec 28, 2010 at 2:54 PM, Enih Gilead  wrote:

Hi, Abrahamsen!

Would you mind tell me a way to eliminate the blank space in front of "a"
[int number] ?
Just as an example, the 'a' that is made = to '0', when printed, it comes
with a blank space after...

a, b = 0, 1
while b<  10:
print a, b,
a, b = a, b + 1

... do you think is there any reasonable way to transform the '0' number
into string and then back to numeral - after the printing action?


If you put commas between things in a print statement, python will put
a space in between. Either use string formatting or convert to str()
and add together:

print "{0}{1}".format(a, b),
print str(a) + str(b),

Hugo


--
Shalom be'Shem 'Adonay, Enih Gil'ead
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python 2.7.1 interpreter passing function pointer as function argument and Shedskin 0.7

2010-12-28 Thread Frank Chang
   Good afternoon. I want to thank everyone who helped me fix the global
name 'levinshtein_automata' is not defined error.
   When I run the Shedskin 0.7 Python to C+++ compiler on the
same python program, I receive the error message * Error *
automata_test.py:148 : unbound identifier 'lookup_func'. lookup_func is a
python function pointer passed as an argument to a python function.
  I have marked lines 148,161,172 and 174 in the python program
automata_test.py shown below. The shedskin tutorial says  the latest version
of the Shedskin 0.7 Python to C++ compiler does not support overloading
__iter__ and __call__.  I was wondering if anyone could suggest a python
workaround to this error message as I am new to python. Thank you.

# automata_test.py
 import bisect
import random
class NFA(object):
 EPSILON = object()
 ANY = object()
 def __init__(self, start_state):
 self.transitions = {}
  self.final_states = set()
  self._start_state = start_state
 @property
 def start_state(self):
return frozenset(self._expand(set([self._start_state])))
 def add_transition(self, src, input, dest):
self.transitions.setdefault(src, {}).setdefault(input, set()).add(dest)

 def add_final_state(self, state):
self.final_states.add(state)
 def is_final(self, states):
return self.final_states.intersection(states)
 def _expand(self, states):
frontier = set(states)
while frontier:
   state = frontier.pop()
   new_states = self.transitions.get(state, {}).get(NFA.EPSILON,
set()).difference(states)
  frontier.update(new_states)
   states.update(new_states)
return states
 def next_state(self, states, input):
dest_states = set()
for state in states:
  state_transitions = self.transitions.get(state, {})
  dest_states.update(state_transitions.get(input, []))
  dest_states.update(state_transitions.get(NFA.ANY, []))
return frozenset(self._expand(dest_states))
 def get_inputs(self, states):
inputs = set()
for state in states:
   inputs.update(self.transitions.get(state, {}).keys())
return inputs
 def to_dfa(self):
   dfa = DFA(self.start_state)
   frontier = [self.start_state]
   seen = set()
   while frontier:
  current = frontier.pop()
  inputs = self.get_inputs(current)
  for input in inputs:
if input == NFA.EPSILON: continue
   new_state = self.next_state(current, input)
   if new_state not in seen:
  frontier.append(new_state)
  seen.add(new_state)
  if self.is_final(new_state):
dfa.add_final_state(new_state)
   if input == NFA.ANY:
  dfa.set_default_transition(current, new_state)
   else:
  dfa.add_transition(current, input, new_state)
   return dfa


class DFA(object):
def __init__(self, start_state):
self.start_state = start_state
self.transitions = {}
self.defaults = {}
self.final_states = set()
def add_transition(self, src, input, dest):
self.transitions.setdefault(src, {})[input] = dest
def set_default_transition(self, src, dest):
self.defaults[src] = dest
def add_final_state(self, state):
self.final_states.add(state)
def is_final(self, state):
return state in self.final_states
def next_state(self, src, input):
state_transitions = self.transitions.get(src, {})
return state_transitions.get(input, self.defaults.get(src, None))
def next_valid_string(self, input):
   state = self.start_state
   stack = []
  # Evaluate the DFA as far as possible
   print state
   for i, x in enumerate(input):
  print "%s" % input
  print 'e'
  stack.append((input[:i], state, x))
  state = self.next_state(state, x)
  if not state: break
else:
  stack.append((input[:i+1], state, None))

if self.is_final(state):
 # Input word is already valid
 return input
  # Perform a 'wall following' search for the lexicographically
smallest
  # accepting state.
 while stack:
 path, state, x = stack.pop()
 x = self.find_next_edge(state, x)
 #print 'x'
if x:
  path += x
state = self.next_state(state, x)
  if self.is_final(state):
 print 'p'
 return path
 stack.append((path, state, None))
 print 'v'
 return None
def find_next_edge(self, s, x):
if x is None:
x = '\0'
else:
x = chr(ord(x) + 1)
state_transitions = self.transitions.get(s, {})
 if x in state_transitions or s in self.defaults:
   return x
labels = sorted(state_transitions.keys())
pos = bisect.bisect_left(labels, x)
if pos < len(labels):
   print 'n'
   return labels[pos]
return None
def levenshtein_automata(self, term, k):
 print 's'
 nfa = NFA((0, 0))
 for i, c in enumerate(term):
for e in range(k + 1):
 # Correct ch

Re: [Tutor] blank space after a number

2010-12-28 Thread bob gailer

On 12/28/2010 2:36 PM, Alan Gauld wrote:


"Enih Gilead"  wrote

Just as an example, the 'a' that is made = to '0', when printed, it 
comes with a blank space after...


a, b = 0, 1
while b < 10:
print a, b,
a, b = a, b + 1

... do you think is there any reasonable way to transform the '0' 
number into string and then back to numeral - after the printing action?


You can use string formatting to create the string any way tou want:

print "%d%d" % a,b


Erm... print "%d%d" % (a,b)


will print 01

Or you can use string conversion and catenastion:

print str(a)+str(b)

to get a similar result.

Incidentally your loop would be clearer if you omited the tuple 
assignment:


while b < 10:
print a, b,
b +=  1

And if you only use 'a' to zero pad the number you can do that with
string formatting too:

print "%02d" % b


Personally I'd go for string formatting because of its much more
powerful and flexible options.





--
Bob Gailer
919-636-4239
Chapel Hill NC

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Choice of Python

2010-12-28 Thread Jeff Johnson


On 12/28/2010 01:35 PM, Brett Ritter wrote:

On Tue, Dec 28, 2010 at 3:06 PM, Jeff Johnson  wrote:

Webfaction supports long processes and that is why they are the largest
Django hosting site.  They support a ton of software, too.  SVN, Trac are
two I use.

I didn't see git hosting among their software.  Is it available
without hoop-jumping?


I counted 20 what they call "applications" of which git is one.  So, yes 
it is there.



Jeff

---

Jeff Johnson
j...@dcsoftware.com




___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Choice of Python

2010-12-28 Thread Brett Ritter
On Tue, Dec 28, 2010 at 3:06 PM, Jeff Johnson  wrote:
> Webfaction supports long processes and that is why they are the largest
> Django hosting site.  They support a ton of software, too.  SVN, Trac are
> two I use.

I didn't see git hosting among their software.  Is it available
without hoop-jumping?
-- 
Brett Ritter / SwiftOne
swift...@swiftone.org
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Choice of Python

2010-12-28 Thread Jeff Johnson


On 12/28/2010 12:48 PM, Marc Tompkins wrote:
On Tue, Dec 28, 2010 at 10:32 AM, > wrote:


Most of the hosting companies I've investigated support older
versions of Python and only support CGI access.

Ah yes - that's what it was.  To use Django (or most other frameworks) 
you need some processes to be running more or less constantly, as 
opposed to in a CGI context.  Your typical shared Webhosting service 
is sharing a single machine or VM with lots of other customers; they 
can't allow long-running processes or the whole thing would grind to a 
halt.  I have no idea how Webfaction manages it, especially with a 
starting price of $5.50/month - it's very tempting...


For the time being I'm not looking to move any sites over - but if the 
need arises again, Webfaction will be the first place I check out.


Actually, my own website is a few years overdue for a facelift - maybe 
I'll dump Joomla for Django.  Perhaps then I'd actually be interested 
enough to maintain the damn thing.


--
www.fsrtechnologies.com 




Webfaction supports long processes and that is why they are the largest 
Django hosting site.  They support a ton of software, too.  SVN, Trac 
are two I use.


I've been with them at least 3 years and I find their cost amazing for 
what I get!  Their documentation, support and forums are about the best 
I've seen.


Jeff

---

Jeff Johnson
j...@dcsoftware.com





___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Choice of Python

2010-12-28 Thread Marc Tompkins
On Tue, Dec 28, 2010 at 10:32 AM,  wrote:

>
> Most of the hosting companies I've investigated support older versions of
> Python and only support CGI access.
>
> Ah yes - that's what it was.  To use Django (or most other frameworks) you
need some processes to be running more or less constantly, as opposed to in
a CGI context.  Your typical shared Webhosting service is sharing a single
machine or VM with lots of other customers; they can't allow long-running
processes or the whole thing would grind to a halt.  I have no idea how
Webfaction manages it, especially with a starting price of $5.50/month -
it's very tempting...

For the time being I'm not looking to move any sites over - but if the need
arises again, Webfaction will be the first place I check out.

Actually, my own website is a few years overdue for a facelift - maybe I'll
dump Joomla for Django.  Perhaps then I'd actually be interested enough to
maintain the damn thing.

-- 
www.fsrtechnologies.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] blank space after a number

2010-12-28 Thread Alan Gauld


"Enih Gilead"  wrote

Just as an example, the 'a' that is made = to '0', when printed, it 
comes with a blank space after...


a, b = 0, 1
while b < 10:
print a, b,
a, b = a, b + 1

... do you think is there any reasonable way to transform the '0' 
number into string and then back to numeral - after the printing 
action?


You can use string formatting to create the string any way tou want:

print "%d%d" % a,b

will print 01

Or you can use string conversion and catenastion:

print str(a)+str(b)

to get a similar result.

Incidentally your loop would be clearer if you omited the tuple 
assignment:


while b < 10:
print a, b,
b +=  1

And if you only use 'a' to zero pad the number you can do that with
string formatting too:

print "%02d" % b


Personally I'd go for string formatting because of its much more
powerful and flexible options.


--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] blank space after a number

2010-12-28 Thread bob gailer

On 12/28/2010 8:54 AM, Enih Gilead wrote:

Hi, Abrahamsen!

Would you mind tell me a way to eliminate the blank space in front of 
"a" [int number] ?
Just as an example, the 'a' that is made = to '0', when printed, it 
comes with a blank space after...


a, b = 0, 1
while b < 10:
print a, b,
a, b = a, b + 1

... do you think is there any reasonable way to transform the '0' 
number into string and then back to numeral - after the printing action?


Use formatting: print '%i%i' % (a,b)



--
Bob Gailer
919-636-4239
Chapel Hill NC

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] blank space after a number

2010-12-28 Thread Hugo Arts
On Tue, Dec 28, 2010 at 2:54 PM, Enih Gilead  wrote:
> Hi, Abrahamsen!
>
> Would you mind tell me a way to eliminate the blank space in front of "a"
> [int number] ?
> Just as an example, the 'a' that is made = to '0', when printed, it comes
> with a blank space after...
>
> a, b = 0, 1
> while b < 10:
>    print a, b,
>    a, b = a, b + 1
>
> ... do you think is there any reasonable way to transform the '0' number
> into string and then back to numeral - after the printing action?
>

If you put commas between things in a print statement, python will put
a space in between. Either use string formatting or convert to str()
and add together:

print "{0}{1}".format(a, b),
print str(a) + str(b),

Hugo
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] blank space after a number

2010-12-28 Thread Enih Gilead

Hi, Abrahamsen!

Would you mind tell me a way to eliminate the blank space in front of 
"a" [int number] ?
Just as an example, the 'a' that is made = to '0', when printed, it 
comes with a blank space after...


a, b = 0, 1
while b < 10:
print a, b,
a, b = a, b + 1

... do you think is there any reasonable way to transform the '0' number 
into string and then back to numeral - after the printing action?


Thanks beforehand ve'Shalom be'Shem 'Adonay,
Enih Gil'ead
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Choice of Python

2010-12-28 Thread Jeff Johnson


On 12/28/2010 10:46 AM, Marc Tompkins wrote:
I love, love, love me some Python - it fits the way I think better 
than any other language I've used - but there is one consideration 
that occurs to me: Python is nearly ubiquitous on Linux/Mac, and easy 
to download and install on Windows - but most bargain-basement Web 
hosts don't support it (I'm looking at YOU, GoDaddy.)


If you're using a premium hosting company ("premium" doesn't 
necessarily mean "extremely expensive", but you do need to compare 
hosting plans), or if you plan on hosting your site yourself, then I 
would absolutely recommend Python (with or without Django or 
what-have-you) for Web development... but if you plan on using 
GoDaddy, stick with PHP.



I have been a software developer since the 70's.  I have used most of 
the major languages.  I used FoxPro for the last 20 years and have 
recently moved to Python.  I absolutely love working with Python!  
Everything works, deployment is easy, and with all of the libraries 
available; there isn't much you can't do.  I now develop on Ubuntu even 
though my customers (and deployment) are Windows.


Check out Webfaction for a hosting company.  They are probably the 
largest Django host, but using their control panel to do things is very 
easy!  I have been using them for over two years.


Jeff

---

Jeff Johnson
j...@dcsoftware.com


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Choice of Python

2010-12-28 Thread python
Marc/Emile,

If you're looking for a good hosting service that supports
Python, I strongly recommend webfaction.com.

I've worked with a lot of hosting companies and webfaction gets
my highest endorsement: Great support, helpful user community,
very flexible support for hosting Python applications from
vanilla CGI to WSGI to Python web frameworks with long running
processes such as Django, CherryPy, web2py, etc, and the latest
versions of Python.

Most of the hosting companies I've investigated support older
versions of Python and only support CGI access.

Malcolm
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Choice of Python

2010-12-28 Thread Marc Tompkins
On Tue, Dec 28, 2010 at 9:56 AM, Emile van Sebille  wrote:

> On 12/28/2010 9:46 AM Marc Tompkins said...
>
>  I love, love, love me some Python - it fits the way I think better than
>> any
>> other language I've used - but there is one consideration that occurs to
>> me:
>> Python is nearly ubiquitous on Linux/Mac, and easy to download and install
>> on Windows - but most bargain-basement Web hosts don't support it (I'm
>> looking at YOU, GoDaddy.)
>>
>> If you're using a premium hosting company ("premium" doesn't necessarily
>> mean "extremely expensive", but you do need to compare hosting plans), or
>> if
>> you plan on hosting your site yourself, then I would absolutely recommend
>> Python (with or without Django or what-have-you) for Web development...
>> but
>> if you plan on using GoDaddy, stick with PHP.
>>
>>
> http://help.godaddy.com/article/809 would seem to indicate differently...
>
> Emile
>
> H!  That's new since I last looked into it.  Color me intrigued...

Has anybody tried GoDaddy's Python support?
-- 
www.fsrtechnologies.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Choice of Python

2010-12-28 Thread Marc Tompkins
On Tue, Dec 28, 2010 at 9:46 AM, Marc Tompkins wrote:

> I love, love, love me some Python - it fits the way I think better than any
> other language I've used - but there is one consideration that occurs to me:
> Python is nearly ubiquitous on Linux/Mac, and easy to download and install
> on Windows - but most bargain-basement Web hosts don't support it (I'm
> looking at YOU, GoDaddy.)
>
> If you're using a premium hosting company ("premium" doesn't necessarily
> mean "extremely expensive", but you do need to compare hosting plans), or if
> you plan on hosting your site yourself, then I would absolutely recommend
> Python (with or without Django or what-have-you) for Web development... but
> if you plan on using GoDaddy, stick with PHP.
>

I sent that too fast: I should clarify.  From your mention of CakePHP, Zend,
and ASP.Net I assume you're mainly interested in Web development.

For desktop development, embedded scripting, or almost any situation where
you can install your own software - I recommend Python wholeheartedly.  I
jumped into it a few years ago when I had a legacy flat-file database I
needed to write reports against, and no native tools to do it with.  I had
my first report written within four or five hours of downloading Python, and
I've been hooked ever since.

-- 
www.fsrtechnologies.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Choice of Python

2010-12-28 Thread Emile van Sebille

On 12/28/2010 9:46 AM Marc Tompkins said...

I love, love, love me some Python - it fits the way I think better than any
other language I've used - but there is one consideration that occurs to me:
Python is nearly ubiquitous on Linux/Mac, and easy to download and install
on Windows - but most bargain-basement Web hosts don't support it (I'm
looking at YOU, GoDaddy.)

If you're using a premium hosting company ("premium" doesn't necessarily
mean "extremely expensive", but you do need to compare hosting plans), or if
you plan on hosting your site yourself, then I would absolutely recommend
Python (with or without Django or what-have-you) for Web development... but
if you plan on using GoDaddy, stick with PHP.



http://help.godaddy.com/article/809 would seem to indicate differently...

Emile


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Choice of Python

2010-12-28 Thread Marc Tompkins
I love, love, love me some Python - it fits the way I think better than any
other language I've used - but there is one consideration that occurs to me:
Python is nearly ubiquitous on Linux/Mac, and easy to download and install
on Windows - but most bargain-basement Web hosts don't support it (I'm
looking at YOU, GoDaddy.)

If you're using a premium hosting company ("premium" doesn't necessarily
mean "extremely expensive", but you do need to compare hosting plans), or if
you plan on hosting your site yourself, then I would absolutely recommend
Python (with or without Django or what-have-you) for Web development... but
if you plan on using GoDaddy, stick with PHP.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Choice of Python

2010-12-28 Thread Knacktus

Am 28.12.2010 14:41, schrieb Stefan Behnel:

Abdulhakim Haliru, 28.12.2010 13:38:

I come from a Cakephp, zend framework angle cutting through ASP.net,VB
and
C# at an intermediate level.
[...]
Is python really worth the pain or should I just skip it ?


Given that you already invested your time into learning all of the above
(which basically cover about 1 1/2 of several main corners of
programming), I think you should really take some time off to unlearn
some of the bad habits that these particular languages tend to teach
you. Python is a truly good way to do that.

My advice: don't spend too much time reading books. Pick a task that
sounds like fun to implement and give it a try with Python. Some would
propose exercises from project Euler for this or maybe pygame, but
you'll likely have your own idea about what's fun and what isn't.
+1 for jumping into coding. You seem to have enough experience in 
programming generally. With Python the fun comes with the experienced 
productivity. At least, that was the case with me.
Learning the syntax is not the deal, but how to design your app. You can 
use the best of OO, functional and procedural programming.
Also, Python is to me the best general purpose language. You can create 
little helper scripts, web apps and rich client apps with PyQt or WxPython.




Stefan

___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Choice of Python

2010-12-28 Thread शंतनू

On 28-Dec-2010, at 10:14 PM, Wayne Werner wrote:

> On Tue, Dec 28, 2010 at 10:05 AM, Brett Ritter  wrote:
>  (though I have to constantly reteach myself not to
> use semicolons :) ). 
> 
> Technically speaking, you *can* use semicolons in Python:
> 
> if 3 == int('3'):
>print('Cool');
> 
> works the same sans semicolon.

And so does following...

>>> if 3 == int('3'):
... print 'hello';print 'world'
... 
hello
world
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Choice of Python

2010-12-28 Thread Wayne Werner
On Tue, Dec 28, 2010 at 10:05 AM, Brett Ritter wrote:

>  (though I have to constantly reteach myself not to
> use semicolons :) ). 


Technically speaking, you *can* use semicolons in Python:

if 3 == int('3'):
   print('Cool');

works the same sans semicolon.

-Wayne
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Choice of Python

2010-12-28 Thread Brett Ritter
On Tue, Dec 28, 2010 at 7:38 AM, Abdulhakim Haliru
 wrote:
> Unlearn my php ways (as that must certainly happen J)  and learn python and
> web development woth python, Jquery etal ?
...
> Is python really worth the pain or should I just skip it ?

If you accept that you'll continue to learn new syntaxes throughout
your career, then the "pain" of python isn't notably different than
any other language (though I have to constantly reteach myself not to
use semicolons :) ).   You aren't "unlearning" so much as
"meta-learning"

That covers the "pain" half of your equation.  As for the Python half
--- Python is pretty widely used in a variety of ways.  It's probably
the most common plugin language for outside utilities (not that
anything is particularly standard in that landscape).  I've noticed
that new language development often compares against Python.
Scientific fields work more and more with Python.

Python won't be your last stop, but it's a valuable one.  As to HOW
valuable, that depends on a bunch of life details we don't know.  If
you want one language to focus on and use exclusively for several
years, Python may or may not be the best choice depending on your
field.  If you want a useful tool that will improve your understanding
of other tools in addition to being useful in its own right, Python is
absolutely a good choice.

All that said, I doubt you'll find many Python Nay-sayers on the
Python Tutors mailing list :)
-- 
Brett Ritter / SwiftOne
swift...@swiftone.org
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Choice of Python

2010-12-28 Thread Emile van Sebille

On 12/28/2010 4:38 AM Abdulhakim Haliru said...


Is python really worth the pain or should I just skip it ?


I think exactly the same thing about PHP each time I run into a PHP app 
that I need to tweak.  Mostly I just skip it...


For me, there wasn't any pain in learning python.  Of course, I started 
12 or so years ago after a very painful two weeks with Java.  I had the 
python version running two days later.


Regards,

Emile

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Choice of Python

2010-12-28 Thread Octavian Rasnita
From: "Abdulhakim Haliru" 
> Hi Guys,
> 
> I am pretty new to python as this is just my 5th day reading through God
> knows how many books. I am really not new to programming, 
> 
> I come from a Cakephp, zend framework angle cutting through ASP.net,VB and
> C# at an intermediate level.
> 
> However, for some reason, I am thinking python but reading through lots of
> the input on forums like quora , keeps me confuse as to  whether to
> continue,
> 
> Unlearn my php ways (as that must certainly happen J)  and learn python and
> web development woth python, Jquery etal ?
> 
> I just need a quick opinion, I know geeks would always favour technologies
> they are used to in forums but then  what do you guys advise ?
> 
> Is python really worth the pain or should I just skip it ?
> 
> Thank you so much.
> 
> Abdulhakim Haliru


It depends on what you want to do.
If you want to create just simple low level apps that use mainly the 
functions/methods provided by the language distribution without installing 
other libraries, PHP is the best.

But you said something about CakePHP so you might be interested in more complex 
apps that use a framework, maybe an ORM and other things...

In this case, Python is much better than PHP. Its syntax is much different than 
the syntax of other languages because it is based on indentation like in the 
old days of Cobol, but the language is much more sane than PHP.

Python is a more general language than PHP and it is not specialized for the 
web so you can do much more things with it than just create web apps.
For creating web apps Perl and Ruby are better than Python, but Python offers a 
much better support for Windows apps and for desktop apps in general than Perl 
and Ruby.

Of course, the comparison is not made only among the features provided by the 
core language, but it takes into account all the modules, libraries, 
frameworks, ORMS, form processors, templating systems that can be used.

The advantages also depend on your preferences. If you like to have a framework 
that forces you to use just a single ORM or a single templating system, you 
might prefer something, and if you like that framework to allow you to use any 
templating system, any ORM, any form processor you can choose... you may like 
another framework.

For example, I have tested more PHP frameworks and I didn't like their very 
limited URL dispatching possibilities.
Some of them even require to define a separate file with URL maps which is ugly 
and hard to maintain, there is no a very powerful ORM for PHP yet, some of them 
use their own templating system which is very limited and other things like 
these.

So yes, if you need to use higher level code, there are better possibilities 
than those offered by PHP, even they are harder to learn.

Octavian

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Choice of Python

2010-12-28 Thread Stefan Behnel

Abdulhakim Haliru, 28.12.2010 13:38:

I come from a Cakephp, zend framework angle cutting through ASP.net,VB and
C# at an intermediate level.
[...]
Is python really worth the pain or should I just skip it ?


Given that you already invested your time into learning all of the above 
(which basically cover about 1 1/2 of several main corners of programming), 
I think you should really take some time off to unlearn some of the bad 
habits that these particular languages tend to teach you. Python is a truly 
good way to do that.


My advice: don't spend too much time reading books. Pick a task that sounds 
like fun to implement and give it a try with Python. Some would propose 
exercises from project Euler for this or maybe pygame, but you'll likely 
have your own idea about what's fun and what isn't.


Stefan

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Choice of Python

2010-12-28 Thread Joel Goldstick
Python, to me, is much more self consistent.  It is a language that was
designed with a plan.  PHP to me feels like its more cobbled together.
Python is easier to read, you get much more done in less code.  The build in
data structures are intrinsically connected to coding patterns.

This may seem silly, but its not to me.  Barrier to entry in PHP is fairly
low.  You need to be interested in math, cs, agorithms to enjoy and exploit
python.  This to me is a more interesting group of developers.  I've been
writing software since the late 70s.  the dawn of the pc era.  Back then,
there were very few people who did it.  Some CS majors, some EE types (me)
some physicists, some poets even.  Since then, because of demand, and hype
there are all sorts of people with widely varying interests in programming,
and I find the people I meet who use python are more similar to those I knew
earlier my career.



On Tue, Dec 28, 2010 at 7:38 AM, Abdulhakim Haliru <
abdulhakim.hal...@leproghrammeen.com> wrote:

> Hi Guys,
>
>
>
> I am pretty new to python as this is just my 5th day reading through God
> knows how many books. I am really not new to programming,
>
> I come from a Cakephp, zend framework angle cutting through ASP.net,VB and
> C# at an intermediate level.
>
>
>
> However, for some reason, I am thinking python but reading through lots of
> the input on forums like quora , keeps me confuse as to  whether to
> continue,
>
> Unlearn my php ways (as that must certainly happen J)  and learn python
> and web development woth python, Jquery etal ?
>
>
>
> I just need a quick opinion, I know geeks would always favour technologies
> they are used to in forums but then  what do you guys advise ?
>
>
>
> Is python really worth the pain or should I just skip it ?
>
>
>
> Thank you so much.
>
>
>
>
>
> *Abdulhakim Haliru*
>
> * *
>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>


-- 
Joel Goldstick
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Choice of Python

2010-12-28 Thread Abdulhakim Haliru
Hi Guys,

 

I am pretty new to python as this is just my 5th day reading through God
knows how many books. I am really not new to programming, 

I come from a Cakephp, zend framework angle cutting through ASP.net,VB and
C# at an intermediate level.

 

However, for some reason, I am thinking python but reading through lots of
the input on forums like quora , keeps me confuse as to  whether to
continue,

Unlearn my php ways (as that must certainly happen J)  and learn python and
web development woth python, Jquery etal ?

 

I just need a quick opinion, I know geeks would always favour technologies
they are used to in forums but then  what do you guys advise ?

 

Is python really worth the pain or should I just skip it ?

 

Thank you so much.

 

 

Abdulhakim Haliru

 

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Opening and closing SQLite db

2010-12-28 Thread Noah Hall
>
> > But to be sure, it is perfectly safe and valid to open the database on
> program startup, commit changes during the process and close it

> on exit (or unhandled exception)?


As long as it makes sense to do so, yes. There's no point having an open
connection to a database if there doesn't need to be.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Opening and closing SQLite db

2010-12-28 Thread Timo

On 26-12-10 19:31, Noah Hall wrote:


>Which is suggestible just in case the app or program crashes
during use.

(To O.P)
Indeed, though in such cases you must rely on your programmers 
instinct to make the right decision - what applies for certain 
instances of an application doesn't always conform with what applies 
for other instances. For example, committing every event is hardly 
ideal for something such as a media player, but may be correct for 
something handling vital data to the system.
The user gets some dialogs where he can click a save-button, so that 
looks like a perfect place to commit changes.


But to be sure, it is perfectly safe and valid to open the database on 
program startup, commit changes during the process and close it on exit 
(or unhandled exception)?


Cheers,
Timo


There's no "one fits all feet" rule for such things - as you program 
and develop more and more applications and programs, listen to your 
users, and your bug tests. It'll come almost naturally after a while. 


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor