Re: [Tutor] new to threading, Queues

2013-04-18 Thread Jordan


On 04/18/2013 02:16 AM, Chuck Mayers wrote:
Hi!  I was having a bit of nostalgia today, and thought I'd try to 
write a simple, old school BBS.  I found the 'paramiko' library, and 
I've got something I can SSH into that would have impressed my 1990's 
self.


I found some example code of the "threading" library, and I've managed 
to use it to take multiple incoming connections at once.


I've never done any multithreaded programming, and everything I've 
ever read is essentially "don't do it! It's really hard to get right!"
True it canbe difficult, but how are you supposed to learn if you don't 
try it, and sometimes you need to do two things at once or at least nearly.


Everything I've read today says to use the Queue library
I can't seem to wrap my head around it, though. I've not seen any 
example code that looks like what I'm trying to do.


Some examples of things I'd like to do:
Have one thread open a file (that all threads will want to read/write 
to) and update it

Have one thread broadcast to all other threads a "chat message"


The only way I can think of, with the Queue library, would be the 
following (I know this has to be the "wrong way" to do this):


1. create an object MultiTask which will have methods to handle thread 
sensitive things like "update a file", etc

2. create one instance of it (we'll call it mtask) and add it to the queue
3. each thread, when it needs to, does queue.get() to get that instance
4. the thread then calls whatever it needs to, say 
mtask.update_users_file()

5. then, call queue.put(mtask) to put it back on the queue

Yeah, I am not sure that will work but maybe.  What I did was to model 
the Mediator Pattern kind of, it then controls the queue and assigns the 
workload to multiple threads creating new threads as needed.  Not that 
my way is the best just how I did it.

http://sourcemaking.com/design_patterns/mediator
My Mediator does not follow the design pattern very well, it is called 
dispatcher, and it uses workers to get the Jobs done, jobs are actually 
defined too. Additionally the code is not as good as it could be, 
because I have not used in for many months, but the tests should work.  
It was made with Python3 in mind. It is attached.


so, there is only ever 1 object in the queue. I assume when another 
thread tries to get() it, they block until the other threads are done 
with it.


Will this work? Is there a better way to do this?

Thanks!


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


# -*- coding: utf-8 *-*
# Provides event driven threaded workers and a dispatcher for handling multiple
# tasks simultaneously.
#Import sys for Python version check, before we import and cause a traceback.
import sys
version = sys.hexversion
#Standard Module Imports
import threading
#Version If Statements:
if version <= 0x0205:
print ("""Feral Components: Mediator
This script requires Python 2.5 or newer to run.
""")
sys.exit()
if version <= 0x0300:
from Queue import Queue, Empty
else:
from queue import Queue, Empty
#Non-Standard Module Imports
#Local Module Imports
import mediator  #
#Globals


class Job(object):
# Base Class, used to give jobs to Dispatcher.
def __init__(self, func, concurrent=True, name=None, args=None,
callback=None):
self.worker = None  # This becomes the threaded worker class instance.
self.function = func  # Function to be run.
self.concurrent = concurrent  # Run simultaneous. Boolean
self.arguments = args  # Arguments that are passed to the function.
self.name = name  # The human readable Job name that's used for logging.
self.callback = callback  # The callback that is made when the worker
# joins and terminates.


class ThreadDaemon(threading.Thread):  # DEPRECIATED
# Base Threading Class for Workers. All Workers are Daemons.
# http://docs.python.org/library/threading.html#threading.Thread.daemon
def __init__(self):
print('DEPRECIATED: ThreadDaemon class was depreciated on 4 June 2012.')
threading.Thread.__init__(self)
self.daemon = True
print('Thread: Initialized. As Thread = ' + self.name)

def __del__(self):
print('Thread: Exiting. As Thread = ' + self.name)


class Worker(ThreadDaemon):
# Worker Completes the function given to it as a seperate thread, using the
# Job object.
def __init__(self, job):
#ThreadDaemon.__init__(self)
self.thread = threading.Thread(target=self.run)
self.thread.daemon = True
self.event = None
self.job = job

def run(self):
print('Worker ' + self.job.name + ': Running. As Thread = ' +
  self.thread.name)
if self.job.arguments != None:
self.job.function(self.job.arguments)
else:
self.job.function()

def __del__(self):  # Th

Re: [Tutor] design question (Django?)

2013-04-18 Thread Wayne Werner

On Sun, 14 Apr 2013, Don Jennings wrote:



On Apr 14, 2013, at 7:06 AM, Albert-Jan Roskam wrote:




> Subject: Re: [Tutor] design question (Django?)


On 13/04/13 09:48, Albert-Jan Roskam wrote:


I think I have to make a diagram of this. This stuff is quite hard



Would it also be a good idea to simultaneously make a paper-and-pencil drawing 
of the UI?


Absolutely! Test it with three users. See Jakob Nielsen's brief take on the 
matter:



A recommendation - check out Balsamiq Mockups for UI design. If you plan 
to make this project open source they'll provide you a free license (with 
a bit of documentation, e.g. link to project on Bitbucket/Github/etc with 
a OSI approved license).


They also have a free web demo that's pretty powerful and just nags every 
5 (or 15?) minutes. http://www.balsamiq.com/


I've not found a better tool for doing quick and rough UI mockps!

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


Re: [Tutor] Fwd: Sys.argv read parameters

2013-04-18 Thread Danilo Chilene
On Wed, Apr 17, 2013 at 8:21 PM, Dave Angel  wrote:

>
>  -- Forwarded message --
>> From: Danilo Chilene 
>> Date: Wed, Apr 17, 2013 at 2:17 PM
>> Subject: Re: [Tutor] Sys.argv read parameters
>> To: Danny Yoo 
>>
>>
>> Hello Danny,
>>
>> The part that is changing is just the sys.argv[1]
>> The vars will have always the same content.
>>
>> What I don't want is to have like 255 'ifs' if I have 255 vars.
>>
>>
> Please don't top post. Put your response AFTER the part you're quoting.
>
>
>
>> On Wed, Apr 17, 2013 at 5:03 PM, Danny Yoo 
>> wrote:
>>
>>>
>>> What's the part that's "changing"?  What's the part that stays the same?
>>>
>>>
> Are all the strings going to be identical except for the one letter?  If
> so, then read the better responses here, like those from Danny Yoo
>
>
The strings will always be the same except for the letter.


> So far, you haven't provided any useful input as to what you're really
> looking for.
>
>
>
>
> --
> DaveA
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: Sys.argv read parameters

2013-04-18 Thread Dave Angel

On 04/18/2013 09:21 AM, Danilo Chilene wrote:

On Wed, Apr 17, 2013 at 8:21 PM, Dave Angel  wrote:



  -- Forwarded message --

From: Danilo Chilene 
Date: Wed, Apr 17, 2013 at 2:17 PM
Subject: Re: [Tutor] Sys.argv read parameters
To: Danny Yoo 


Hello Danny,

The part that is changing is just the sys.argv[1]
The vars will have always the same content.

What I don't want is to have like 255 'ifs' if I have 255 vars.



Please don't top post. Put your response AFTER the part you're quoting.




On Wed, Apr 17, 2013 at 5:03 PM, Danny Yoo 
wrote:



What's the part that's "changing"?  What's the part that stays the same?



Are all the strings going to be identical except for the one letter?  If
so, then read the better responses here, like those from Danny Yoo



The strings will always be the same except for the letter.



Then in that case, why do you use any if-test?  Just substitute the 
letter, as Danny pointed out.


You never said whether you accept more than one letter from the command 
line.  I've been assuming you do, since you used a loop.


for letter in sys.argv[1].upper():
print "This is uppercase of one of the input letters, %s" % letter





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


Re: [Tutor] design question (Django?)

2013-04-18 Thread Walter Prins
Hi,


On Sun, 14 Apr 2013, Don Jennings wrote:
>
>
>> On Apr 14, 2013, at 7:06 AM, Albert-Jan Roskam wrote:
>>
>>
>>>
>>> > Subject: Re: [Tutor] design question (Django?)
>>>

 On 13/04/13 09:48, Albert-Jan Roskam wrote:

  I think I have to make a diagram of this. This stuff is quite hard
>

  Would it also be a good idea to simultaneously make a paper-and-pencil
>>> drawing of the UI?
>>>
>>
>> Absolutely! Test it with three users. See Jakob Nielsen's brief take on
>> the matter:
>>
>>
You might check out Pencil, which I quite like.

http://pencil.evolus.vn/

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


[Tutor] path directory backslash ending

2013-04-18 Thread Jim Mooney
Minor question. I was adding the Py Script directory to the Win 7
Path, and noticed that Python33 ends with a backslash but many
directories do not. Is there a difference? Should I use backslash or
not preferentially, or doesn't it matter at all? It does seem odd that
there's no convention for this.

-- 
Jim Mooney

Today is the day that would have been tomorrow if yesterday was today
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] path directory backslash ending

2013-04-18 Thread Dave Angel

On 04/18/2013 12:45 PM, Jim Mooney wrote:

Minor question. I was adding the Py Script directory to the Win 7
Path, and noticed that Python33 ends with a backslash but many
directories do not. Is there a difference? Should I use backslash or
not preferentially, or doesn't it matter at all? It does seem odd that
there's no convention for this.



There's no Python convention.  There may be a Windows convention, but I 
doubt it.  As far as I could tell when I was stuck in Windows, the only 
time a trailing backslash was significant was when there was nothing in 
front of it but a colon and/or a drive letter.


In Linux, applications are free to make their own use of the trailing 
backslash, and I know that rsync does something different with it 
present than without.  But in the PATH, it doesn't matter.


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


Re: [Tutor] Fwd: Sys.argv read parameters

2013-04-18 Thread Danilo Chilene
On Thu, Apr 18, 2013 at 10:31 AM, Dave Angel  wrote:

> On 04/18/2013 09:21 AM, Danilo Chilene wrote:
>
>> On Wed, Apr 17, 2013 at 8:21 PM, Dave Angel  wrote:
>>
>>
>>>   -- Forwarded message --
>>>
 From: Danilo Chilene 
 Date: Wed, Apr 17, 2013 at 2:17 PM
 Subject: Re: [Tutor] Sys.argv read parameters
 To: Danny Yoo 


 Hello Danny,

 The part that is changing is just the sys.argv[1]
 The vars will have always the same content.

 What I don't want is to have like 255 'ifs' if I have 255 vars.


  Please don't top post. Put your response AFTER the part you're quoting.
>>>
>>>
>>>
>>>  On Wed, Apr 17, 2013 at 5:03 PM, Danny Yoo 
 wrote:


> What's the part that's "changing"?  What's the part that stays the
> same?
>
>
>  Are all the strings going to be identical except for the one letter?
>>>  If
>>> so, then read the better responses here, like those from Danny Yoo
>>>
>>>
>>>  The strings will always be the same except for the letter.
>>
>>
> Then in that case, why do you use any if-test?  Just substitute the
> letter, as Danny pointed out.
>
> You never said whether you accept more than one letter from the command
> line.  I've been assuming you do, since you used a loop.
>
> for letter in sys.argv[1].upper():
> print "This is uppercase of one of the input letters, %s" % letter


Below is the final code:

import requests, json, sys

r = requests.get('http://napmongo01.cvc.com.br:28017/_status')
j = r.json()

arg = sys.argv[1]

commands = {
'uptime' : "j['serverStatus']['uptime']"
'globalLock_lockTime' :
"j['serverStatus']['globalLock']['lockTime']"
'globalLock_currentQueue_total' =
"j['serverStatus']['globalLock']['currentQueue']['total']"
'globalLock_currentQueue_readers' =
"j['serverStatus']['globalLock']['currentQueue']['readers']"
'globalLock_currentQueue_writers' =
"j['serverStatus']['globalLock']['currentQueue']['writers']"
'mem_bits' = "j['serverStatus']['mem']['bits']"
'mem_resident' = "j['serverStatus']['mem']['resident']"
'mem_virtual' = "j['serverStatus']['mem']['virtual']"
'connections_current' =
"j['serverStatus']['connections']['current']"
'connections_available' =
"j['serverStatus']['connections']['available']"
'extra_info_heap_usage' =
round(("j['serverStatus']['extra_info']['heap_usage_bytes'])/(1024*124), 2)"
'extra_info_page_faults' =
"j['serverStatus']['extra_info']['page_faults']"
'indexCounters_btree_accesses' =
"j['serverStatus']['indexCounters']['btree']['accesses']"
'indexCounters_btree_hits' =
"j['serverStatus']['indexCounters']['btree']['hits']"
'indexCounters_btree_misses' =
"j['serverStatus']['indexCounters']['btree']['misses']"
'indexCounters_btree_resets' =
"j['serverStatus']['indexCounters']['btree']['resets']"
'indexCounters_btree_missRatio' =
"j['serverStatus']['indexCounters']['btree']['missRatio']"
'backgroundFlushing_flushes' =
"j['serverStatus']['backgroundFlushing']['flushes']"
'backgroundFlushing_total_ms' =
"j['serverStatus']['backgroundFlushing']['total_ms']"
'backgroundFlushing_average_ms' =
"j['serverStatus']['backgroundFlushing']['average_ms']"
'backgroundFlushing_last_ms' =
"j['serverStatus']['backgroundFlushing']['last_ms']"
'cursors_totalOpen' =
"j['serverStatus']['cursors']['totalOpen']"
'cursors_clientCursors_size' =
"j['serverStatus']['cursors']['clientCursors_size']"
'cursors_timedOut' =
"j['serverStatus']['cursors']['timedOut']"
'opcounters_insert' =
"j['serverStatus']['opcounters']['insert']"
'opcounters_query' =
"j['serverStatus']['opcounters']['query']"
'opcounters_update' =
"j['serverStatus']['opcounters']['update']"
'opcounters_delete' =
"j['serverStatus']['opcounters']['delete']"
'opcounters_getmore' =
"j['serverStatus']['opcounters']['getmore']"
'opcounters_command' =
['server_status']['opcounters']['command']""
'asserts_regular' =
"j['serverStatus']['asserts']['regular']"
'asserts_warning' =
"j['serverStatus']['asserts']['warning']"
'asserts_msg' = "j['serverStatus']['asserts']['msg']"
'asserts_user' = "j['serverStatus']['asserts']['user']"
'asserts_rollovers' =
"j['serverStatus']['asserts']['rollovers']"
'network_inbound_traffic_mb' =
("j['serverStatus']['network']['bytesIn'])/(1024*1024)"
'network_outbound_traffic_mb' =
("j['serverStatus']['network']['bytesOut'])/(1024*1024)"
'network_requests' =
"j['serverStatus']['network']['numReque

Re: [Tutor] Fwd: Sys.argv read parameters

2013-04-18 Thread Dave Angel

On 04/18/2013 01:14 PM, Danilo Chilene wrote:


   


The following code has little to do with anything that happened before. 
 So you should start a new thread for this new project.




Below is the final code:

import requests, json, sys

r = requests.get('http://napmongo01.cvc.com.br:28017/_status')
j = r.json()

arg = sys.argv[1]

commands = {
 'uptime' : "j['serverStatus']['uptime']"
 'globalLock_lockTime' :
"j['serverStatus']['globalLock']['lockTime']"


A literal string that happens to have j in it has nothing at all to do 
with the j that you got from json.



 'globalLock_currentQueue_total' =
"j['serverStatus']['globalLock']['currentQueue']['total']"
 'globalLock_currentQueue_readers' =
"j['serverStatus']['globalLock']['currentQueue']['readers']"
 'globalLock_currentQueue_writers' =
"j['serverStatus']['globalLock']['currentQueue']['writers']"
 'mem_bits' = "j['serverStatus']['mem']['bits']"
 'mem_resident' = "j['serverStatus']['mem']['resident']"
 'mem_virtual' = "j['serverStatus']['mem']['virtual']"
 'connections_current' =
"j['serverStatus']['connections']['current']"
 'connections_available' =
"j['serverStatus']['connections']['available']"
 'extra_info_heap_usage' =
round(("j['serverStatus']['extra_info']['heap_usage_bytes'])/(1024*124), 2)"
 'extra_info_page_faults' =
"j['serverStatus']['extra_info']['page_faults']"
 'indexCounters_btree_accesses' =
"j['serverStatus']['indexCounters']['btree']['accesses']"
 'indexCounters_btree_hits' =
"j['serverStatus']['indexCounters']['btree']['hits']"
 'indexCounters_btree_misses' =
"j['serverStatus']['indexCounters']['btree']['misses']"
 'indexCounters_btree_resets' =
"j['serverStatus']['indexCounters']['btree']['resets']"
 'indexCounters_btree_missRatio' =
"j['serverStatus']['indexCounters']['btree']['missRatio']"
 'backgroundFlushing_flushes' =
"j['serverStatus']['backgroundFlushing']['flushes']"
 'backgroundFlushing_total_ms' =
"j['serverStatus']['backgroundFlushing']['total_ms']"
 'backgroundFlushing_average_ms' =
"j['serverStatus']['backgroundFlushing']['average_ms']"
 'backgroundFlushing_last_ms' =
"j['serverStatus']['backgroundFlushing']['last_ms']"
 'cursors_totalOpen' =
"j['serverStatus']['cursors']['totalOpen']"
 'cursors_clientCursors_size' =
"j['serverStatus']['cursors']['clientCursors_size']"
 'cursors_timedOut' =
"j['serverStatus']['cursors']['timedOut']"
 'opcounters_insert' =
"j['serverStatus']['opcounters']['insert']"
 'opcounters_query' =
"j['serverStatus']['opcounters']['query']"
 'opcounters_update' =
"j['serverStatus']['opcounters']['update']"
 'opcounters_delete' =
"j['serverStatus']['opcounters']['delete']"
 'opcounters_getmore' =
"j['serverStatus']['opcounters']['getmore']"
 'opcounters_command' =
['server_status']['opcounters']['command']""
 'asserts_regular' =
"j['serverStatus']['asserts']['regular']"
 'asserts_warning' =
"j['serverStatus']['asserts']['warning']"
 'asserts_msg' = "j['serverStatus']['asserts']['msg']"
 'asserts_user' = "j['serverStatus']['asserts']['user']"
 'asserts_rollovers' =
"j['serverStatus']['asserts']['rollovers']"
 'network_inbound_traffic_mb' =
("j['serverStatus']['network']['bytesIn'])/(1024*1024)"
 'network_outbound_traffic_mb' =
("j['serverStatus']['network']['bytesOut'])/(1024*1024)"
 'network_requests' =
"j['serverStatus']['network']['numRequests']"
 'write_backs_queued' =
"j['serverStatus']['writeBacksQueued']"
 'logging_commits' = "j['serverStatus']['dur']['commits']"
 'logging_journal_writes_mb' =
"j['serverStatus']['dur']['journaledMB']"
 'logging_datafile_writes_mb' =
"j['serverStatus']['dur']['writeToDataFilesMB']"
 'logging_commits_in_writelock' =
"j['serverStatus']['dur']['commitsInWriteLock']"
 'logging_early_commits' =
"j['serverStatus']['dur']['earlyCommits']"
 'logging_log_buffer_prep_time_ms' =
"j['serverStatus']['dur']['timeMs']['prepLogBuffer']"
 'logging_journal_write_time_ms' =
"j['serverStatus']['dur']['timeMs']['writeToJournal']"
 'logging_datafile_write_time_ms' =
"j['serverStatus']['dur']['timeMs']['writeToDataFiles']"
}

for command in commands:
 if arg in commands:
 print commands[command]
 else:
 print 'Invalid command'


The above loop makes no sense at all for several reasons.  I'd be amazed 
if it happens to 

Re: [Tutor] Fwd: Sys.argv read parameters

2013-04-18 Thread Alan Gauld

On 18/04/13 18:14, Danilo Chilene wrote:


for command in commands:
 if arg in commands:
 print commands[command]
 else:
 print 'Invalid command'


I don't understand what you are doing here? Its almost a random 
selection mechanism? You print the command for every item in commands if 
arg is in commands and Invalid Command for every command if its not?

Whatever its trying to do its massively inefficient.

I thought you'd have wanted something like

 for command in commands:
  if arg == command:
  print commands[command]
  else:
  print 'Invalid command'

Which is roughly equivalent to:

print commands.get(arg, 'Invalid command')

but much less efficient!


--
Alan G
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] Fwd: Sys.argv read parameters

2013-04-18 Thread Danilo Chilene
On Thu, Apr 18, 2013 at 2:52 PM, Alan Gauld wrote:

> On 18/04/13 18:14, Danilo Chilene wrote:
>
>  for command in commands:
>>  if arg in commands:
>>  print commands[command]
>>  else:
>>  print 'Invalid command'
>>
>
> I don't understand what you are doing here? Its almost a random selection
> mechanism? You print the command for every item in commands if arg is in
> commands and Invalid Command for every command if its not?
> Whatever its trying to do its massively inefficient.
>
> I thought you'd have wanted something like
>
>  for command in commands:
>   if arg == command:
>
>   print commands[command]
>   else:
>   print 'Invalid command'
>
> Which is roughly equivalent to:
>
> print commands.get(arg, 'Invalid command')
>
> but much less efficient!

Hi Alan,

Yes, I was doing it the wrong way.


>
>
>
> --
> Alan G
> 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
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: Sys.argv read parameters

2013-04-18 Thread Danny Yoo
Ok, good.  This is _much_ more realistic code, and demonstrates why
seeing context is important.


My suggestion to do it computationally is totally invalid here.  :P
There's a lot of variation here, due to the access paths through the
JSON that you're walking.  You're essentially defining a very
lightweight domain-specific language, technically.  The semantics of
the commands appear to be: walk the JSON of a certain path.  A
dispatch table here is _very_ appropriate.

The values in your dispatch table, however, should not be literal code
that you want to evaluate: rather, they should just hold an inert
path.  The act of using the dispatch table should take a path and then
apply it to the JSON in question.

(I am trying _very_ hard not to say the word "eval" here, because it's
just dangerous in this context.)

Here's what the interpretation part of your language might looks like:

#
def p(*elts):
"""Construct a representation of a path.
(We'll cheat a little by using a list of strings.)"""
return elts

commands = {
'uptime' : p('serverStatus', 'uptime'),
'globalLock_lockTime' : p('serverStatus', 'globalLock', 'lockTime')
## Fill me in with more elements.
}

def lookup(data, cmdName):
path = commands[cmdName]
for p in path:
data = data[p]
return data

## For example, let's mock up some sample data and see how this works.

sampleData = {'serverStatus' : {'uptime': 3,
'cpu load' : 1.11,
'globalLock' : { 'lockName' : 'sample
lock name',
 'lockTime' : 42 }}}
print lookup(sampleData, 'uptime')
print lookup(sampleData, 'globalLock_lockTime')
#


You should be able to see how to extend this to your realistic
example: just add more entries in your command.  Note that I'm using a
function p() to construct the path: that's just for my own
convenience: you might be able to just strip it out and inline the
paths directly into the table.

(But having p there enables maintenance: we might need to extend the
system to do more than path lookup later on, in which case redefining
p makes it easy to change the representation of paths by modifying a
single place.)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: Sys.argv read parameters

2013-04-18 Thread Danny Yoo
Followup: compare the previous interpreter code with this revision:

https://gist.github.com/dyoo/5415464

and you'll see how it becomes easier now to add new command types into
the system.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] path directory backslash ending

2013-04-18 Thread eryksun
On Thu, Apr 18, 2013 at 12:45 PM, Jim Mooney  wrote:
> Minor question. I was adding the Py Script directory to the Win 7
> Path, and noticed that Python33 ends with a backslash but many
> directories do not. Is there a difference? Should I use backslash or
> not preferentially, or doesn't it matter at all? It does seem odd that
> there's no convention for this.

The trailing backslash shouldn't directly matter in the PATH variable,
not as far how the system splits the string on ';' and searches the
directories. It may be an issue with escaping if "%PATH%" is passed as
a quoted argument. We can test this to be sure. Create test.py:

import sys
print(sys.argv[1:])

Now try an example. First without quotes:

C:\>test.py C:\Program Files;C:\Python33\
['C:\\Program', 'Files;C:\\Python33\\']

Obviously the C runtime (not the shell, as would be the case on a
POSIX system)  needs a little help parsing the argument string. We'll
add some quotes around it:

C:\>test.py "C:\Program Files;C:\Python33\"
['C:\\Program Files;C:\\Python33"']

Ack! The trailing backslash was treated as an escape character, so we
end up with a trailing double quote. It works fine if you remove the
trailing backslash:

C:\>test.py "C:\Program Files;C:\Python33"
['C:\\Program Files;C:\\Python33']

OK, so IMHO don't use a trailing backslash.

It's also a convention to not use a trailing backslash in directories
set as environment variables. For example:

C:\>echo %ProgramFiles%
C:\Program Files

This makes it look more natural as part of another path:

C:\>dir /b "%ProgramFiles%\Microsoft SDKs\Windows\v7.0A"
bin
Include
Lib

Note that the shell replaces %ProgramFiles% literally with C:\Program
Files, so quotes are required.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] path directory backslash ending

2013-04-18 Thread Jim Mooney
Well, under the principle of least  harm, it appears that since the
trailing backslash causes no harm if omitted, but sometimes does if
allowed, I removed them all.

But that's in win 7. Is it okay to always omit them in Linux? Python33
is itself installed with a trailing backslash, so I figured this was a
Linux habit.

An entirely different question as long as I'm here. I have a local
wamp server with mysql and phpadmin for php so I can test web pages
locally. What's the equivalent for Python?

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