Re: [Tutor] Running Existing Python

2011-02-26 Thread Justin Bonnell
Okay. When I try to run the script from the terminal, it still doesn't work. 
Here is a screenshot.

inline: Screen shot 2011-02-26 at 12.47.02 AM.png
What am I doing wrong?


On Feb 25, 2011, at 6:46 PM, Alan Gauld wrote:

 
 Justin Bonnell jwbonne...@gmail.com wrote
 
 Python 2.7.1 (r271:86882M, Nov 30 2010, 10:35:34) [GCC 4.2.1 (Apple Inc. 
 build 5664)] on darwin
 Type copyright, credits or license() for more information.
 
 The  prompt means you are already inside Python.
 You can type Python commands at the  prompt, things like
 
 print Hello
 
 But you cannot ruin a program from inside the  prompt (well, you can, but 
 its more complicated than sane people want to bother with! :-)
 
 You run a Python script from the OS Terminal prompt:
 
 $ python hello.py
 
 Shouldn't I be able to run hello.py from the IDLE interpreter?
 
 You can't run it from the  prompt in IDLE but
 What you can do is open the file for editing and then run that file using the 
 menu commands, then the output will show up in the interpreter window.
 
I get how to do this now^^
 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

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


Re: [Tutor] accessing another system's environment

2011-02-26 Thread ALAN GAULD
Bill,

That's the same thing we are talking about.
The problem is those environment variables are
highly variable so you can't talk about a machine's environment.
Two users on the same machine (at the same time) may have 
very different environments. And a batch file or program can 
add or remove variables too. So when I run python2 I may have
the PYTHONPATH seet to one thing, but if I run python3 I 
have it set to something different. And I could be running 
both at the same time. And another user (or service)  logged 
into the same machine might be running a Django web server with 
yet another setting. So what is PYTHONPATH for that machine?

The USER and HOME Values are set by the OS to different 
values depending on who is logged in, but the user can 
then change these later, etc...


Even with no users logged in you might have different services 
running each with their own environment set up.

It is very difficult for an admin to do anything reliably 
based on environment variable settings.

Alan Gauld
Author of the Learn To Program website
http://www.alan-g.me.uk/




From: Bill Allen walle...@gmail.com
To: Alan Gauld alan.ga...@btinternet.com
Cc: tutor@python.org
Sent: Saturday, 26 February, 2011 2:50:39
Subject: Re: [Tutor] accessing another system's environment

I apologize for not have been clear previously.   What I am trying to access 
are 
the Windows system environment variables.   The same ones that are listed out 
if 
you type the set command at a command prompt in Windows. 



--Bill






On Fri, Feb 25, 2011 at 03:11, Alan Gauld alan.ga...@btinternet.com wrote:


Bill Allen walle...@gmail.com wrote


I have times when it is useful for me to check the environment of a user
system on our lan remotely while trouble shooting and issue with them.  Now,
this is quite easy to do while I am using a windows system via the computer
management console.


I think we are meaning different things by environment?
Can you give a specific example?



However, I am trying to do this via a linux workstation
(which is joined to the domain, etc.).   I cannot find a native
facility to duplicate the computer management functions, so I thought I
would write a program to fill the need.


Anything you can do locally you can do on the remote
machine with a combination of ssh, rsh, rlogin, telnet etc.
ssh is the safest but requires a bit more admin to set it
up properly for maximum convenience.

Having got remote access its just a case of figuring out
which of the 500 or so Unix commands you need to
use to do the job... :-)


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

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


Re: [Tutor] Running Existing Python

2011-02-26 Thread ALAN GAULD
The error says it can't find the file hello.py.
That means its probably in some other folder 
or you need to specify the full or relative path to the file
This is a MacOS issue not Python, its how your MacOS 
shell is searching for the file.

If it is in the same folder try explicitly telling MacOS:

$ python ./hello.py

Or if it is somewhere else either cd to that folder 
or type the path:

$ python /the/full/path/to/the/dfile/hello.py

There are some environment variables you can 
set in your login script which will help MacOS 
find the files but they depend on which shell 
Terminal is running, tcsh or bash are the usual 
options.

Finally there is a trick you can use on the hello.py 
file that means you can launch the .py file directly 
from Finder. It's called the shebang trick by Unix 
folks.

Basically you add a line like

#! /usr/env/python

To the very top of the file. MacOS will then use that 
command to execute the script. If usr/env doesn't 
work type

$ which python

and copy the output instead of /usr/env

 
Alan Gauld
Author of the Learn To Program website
http://www.alan-g.me.uk/




- Original Message 
 From: Justin Bonnell jwbonne...@gmail.com
 To: Alan Gauld alan.ga...@btinternet.com
 Cc: tutor@python.org
 Sent: Saturday, 26 February, 2011 6:49:37
 Subject: Re: [Tutor] Running Existing Python
 
 Okay. When I try to run the script from the terminal, it still doesn't work.  
Here is a screenshot.
 
 
 What am I doing wrong?
 
 
 On Feb 25,  2011, at 6:46 PM, Alan Gauld wrote:
 
  
  Justin Bonnell jwbonne...@gmail.com wrote
  
  Python 2.7.1 (r271:86882M, Nov 30 2010, 10:35:34) [GCC 4.2.1 (Apple  Inc. 
build 5664)] on darwin
  Type copyright, credits or  license() for more information.
  
  The  prompt means  you are already inside Python.
  You can type Python commands at the   prompt, things like
  
  print  Hello
  
  But you cannot ruin a program from inside the   prompt (well, you can, 
  but 
its more complicated than sane people  want to bother with! :-)
  
  You run a Python script from the OS  Terminal prompt:
  
  $ python hello.py
  
   Shouldn't I be able to run hello.py from the IDLE interpreter?
  
   You can't run it from the  prompt in IDLE but
  What you  can do is open the file for editing and then run that file using 
the menu  commands, then the output will show up in the interpreter window.
  
 I  get how to do this now^^
  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
 
 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] accessing another system's environment

2011-02-26 Thread Steve Willoughby

On 26-Feb-11 01:19, ALAN GAULD wrote:

Bill,

That's the same thing we are talking about.
The problem is those environment variables are
highly variable so you can't talk about a machine's environment.
Two users on the same machine (at the same time) may have
very different environments. And a batch file or program can


I'm a Unix hacker, so forgive me if my understanding of Windows is a bit 
naive.  I think, though, that Windows has a set of environment variables 
which are system-wide, added automatically to the user set of variables 
when a new process is launched.  Yes, they can be changed or deleted but 
there is a standard set applied to all users.


If that's a correct assumption on my part, there must be somewhere that 
can be read from, probably (I would guess) in the registry.  So a script 
which could read/write those registry keys may do what is required here.


The issue of exposing that to remote machines remains a dangling issue, 
though.


Of course, it's not entirely clear we're solving a Python question, 
although this discussion may well go more solidly into that space.



add or remove variables too. So when I run python2 I may have
the PYTHONPATH seet to one thing, but if I run python3 I
have it set to something different. And I could be running
both at the same time. And another user (or service) logged
into the same machine might be running a Django web server with
yet another setting. So what is PYTHONPATH for that machine?

The USER and HOME Values are set by the OS to different
values depending on who is logged in, but the user can
then change these later, etc...

Even with no users logged in you might have different services
running each with their own environment set up.

It is very difficult for an admin to do anything reliably
based on environment variable settings.

Alan Gauld
Author of the Learn To Program website
http://www.alan-g.me.uk/
http://www.alan-g.me.uk


*From:* Bill Allen walle...@gmail.com
*To:* Alan Gauld alan.ga...@btinternet.com
*Cc:* tutor@python.org
*Sent:* Saturday, 26 February, 2011 2:50:39
*Subject:* Re: [Tutor] accessing another system's environment

I apologize for not have been clear previously. What I am trying to
access are the Windows system environment variables. The same ones
that are listed out if you type the set command at a command prompt
in Windows.


--Bill





On Fri, Feb 25, 2011 at 03:11, Alan Gauld alan.ga...@btinternet.com
mailto:alan.ga...@btinternet.com wrote:


Bill Allen walle...@gmail.com mailto:walle...@gmail.com wrote

I have times when it is useful for me to check the
environment of a user
system on our lan remotely while trouble shooting and issue
with them. Now,
this is quite easy to do while I am using a windows system
via the computer
management console.


I think we are meaning different things by environment?
Can you give a specific example?


However, I am trying to do this via a linux workstation
(which is joined to the domain, etc.). I cannot find a native
facility to duplicate the computer management functions, so
I thought I
would write a program to fill the need.


Anything you can do locally you can do on the remote
machine with a combination of ssh, rsh, rlogin, telnet etc.
ssh is the safest but requires a bit more admin to set it
up properly for maximum convenience.

Having got remote access its just a case of figuring out
which of the 500 or so Unix commands you need to
use to do the job... :-)


HTH,

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


___
Tutor maillist - Tutor@python.org mailto: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



--
Steve Willoughby / st...@alchemy.com
A ship in harbor is safe, but that is not what ships are built for.
PGP Fingerprint 48A3 2621 E72C 31D9 2928 2E8F 6506 DB29 54F7 0F53
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Cross-Module Interaction

2011-02-26 Thread Alan Gauld


Corey Richardson kb1...@aim.com wrote


I'm slightly concerned about performance when it comes to
reading/writing to disk a lot when doing things like that, since if 
this

thing ever needs to scale I want it to be able to do that.


There is always an overhead but it depends what you
mean by a lot.

You might choose to only write on updates, only write when
users leave the system, only write when the system closes
down or write periodically (either a timed period or when
certain resource levels get above/below critical levels)

Lots of options. You need to choose a strategy that works
for your situation.

--
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] Running Existing Python

2011-02-26 Thread Dave Angel

On 01/-10/-28163 02:59 PM, Justin Bonnell wrote:

Okay. When I try to run the script from the terminal, it still doesn't work. 
Here is a screenshot.





What am I doing wrong?

1) You're top-posting.  Put your responses after the quote you're 
responding to.


2) You're trying to include graphical images in a text-based newsgroup. 
 Just use copy/paste, and include it in your message.


3) You don't tell us where the hello.py file actually is.  Presumably 
it's not in the current directory when you run that.  Two cures for 
that:  either specify its real location,

 python   ~/mysources/hello.py

or cd to the proper directory.  The latter is usually easier, but it 
depends where other files your script are located.


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


Re: [Tutor] accessing another system's environment

2011-02-26 Thread David
On 25 February 2011 14:30, Bill Allen walle...@gmail.com wrote:

 I have times when it is useful for me to check the environment of a user
 system on our lan remotely while trouble shooting and issue with them.  Now,
 this is quite easy to do while I am using a windows system via the computer
 management console.   However, I am trying to do this via a linux
 workstation (which is joined to the domain, etc.).   I cannot find a native
 facility to duplicate the computer management functions, so I thought I
 would write a program to fill the need.   Not to mention, I thought it might
 be a good learning opportunity.

If I understand correctly, you want to view/change the environment
variables of some user running under some version of Windows while you
are sitting at a remote Linux workstation.

I have just done a test here which might help answer your query. I
have ssh running on this linux box. I have openssh [1] running on
a Windows 2000 sp4 box on my LAN. I can open a terminal on the linux
box and run ssh to remote login to the windows box which then
displays a windows command prompt shell in the terminal where I can
use the dos set command to remotely view/change the windows
environment variables.

I expect that once you have this working interactively, it could be
scripted using python, but I have not tested that.

[1] http://sshwindows.webheat.co.uk
Disclaimer: I personally have zero information about this software
provider. So do not use it without conducting your own investigation
into any security risks that might affect your situation.

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


Re: [Tutor] Cross-Module Interaction

2011-02-26 Thread Walter Prins
On 26 February 2011 05:33, Corey Richardson kb1...@aim.com wrote:

 Aha, that explains why I didn't get any results. Each file got its own
 interpreter instance.


Not wanting to nit pick, but no: It's not that each *file* does has its own
interpreter instance, it's that every python instance that you start does
not automatically persist anything that gets created while it lives. In
other words, you can import many modules (files) into any given interpreter
instance, but whether or not the stuff gets persisted anywhere is a seperate
matter.

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


Re: [Tutor] Cross-Module Interaction

2011-02-26 Thread Walter Prins
On 26 February 2011 05:33, Corey Richardson kb1...@aim.com wrote:


 I'm slightly concerned about performance when it comes to
 reading/writing to disk a lot when doing things like that, since if this
 thing ever needs to scale I want it to be able to do that.


I'd be tempted to say you should not be worrying about such performance
issues at this stage.  Remember what Knuth said, ... premature optimization
is the root of all evil  Suffice it to say you can push rather large
amounts of disk I/O with Python, and you can always come up with creative
caching systems or whatever once you get that far along and it proves to be
a problem.

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


Re: [Tutor] Cross-Module Interaction

2011-02-26 Thread Corey Richardson
On 02/26/2011 06:02 AM, Walter Prins wrote:
 On 26 February 2011 05:33, Corey Richardson kb1...@aim.com wrote:
 
 Aha, that explains why I didn't get any results. Each file got its own
 interpreter instance.

 
 Not wanting to nit pick, but no: It's not that each *file* does has its own
 interpreter instance, it's that every python instance that you start does
 not automatically persist anything that gets created while it lives. In
 other words, you can import many modules (files) into any given interpreter
 instance, but whether or not the stuff gets persisted anywhere is a seperate
 matter.
 
 Walter
 

I ran them like this:
python use1.py
python use2.py
python plib.py

Each file got its own instance of the interpreter.

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


Re: [Tutor] Cross-Module Interaction

2011-02-26 Thread Corey Richardson
On 02/26/2011 06:05 AM, Walter Prins wrote:
 I'd be tempted to say you should not be worrying about such performance
 issues at this stage.  

Indeed, but I can't have every piece of variable information being saved
to disk and then read back again every time a player leaves or enters a
room, that'd just be silly!

Playing MUD's for a bit it gets annoying on a medium-size server when
you have to wait more than 3 seconds just to get how much health you
have after attacking some baddie. I won't be trying to pull every
microsecond of efficiency out of this, but I would like it to be
sensible and now waste time dawdling.

(And the full quote is We should forget about *small* efficiencies, say
about 97% of the time: premature optimization is the root of all evil.
(emphasis added))

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


Re: [Tutor] Cross-Module Interaction

2011-02-26 Thread Walter Prins
On 26 February 2011 11:06, Corey Richardson kb1...@aim.com wrote:

 I ran them like this:
 python use1.py
 python use2.py
 python plib.py

 Each file got its own instance of the interpreter.


Yes, but not because instances are intrinsically linked to seperate python
modules, which is what it sounds like you're saying.  In the above case you
*explicitly* started the 3 python instances seperately yourself from the
command line, giving each instance a file to run, which is why you got 3
seperate instances.  It's nothing to do with the fact that you have 3 files
as such.  (You'd have had 3 instances even if you ran the same file 3
times.)  If you e.g. ran use1.py which then imported or ran use2.py and
use3.py they'd all have used the same instance.  Similarly, if you'd opened
all 3 files in IDLE, and ran them with F5 in turn, they'd all have run in
the *same* interpreter instance.Perhaps you do understand and you've
expressed yourself poorly or I've just miinterpreted what you meant, I just
wanted to make sure you don't think that seperate files (modules) will by
some magic always have their own instances (which is not the case in
general.)

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


Re: [Tutor] accessing another system's environment

2011-02-26 Thread python
Bill,

Coming into this thread late: If you are working with Windows
workstations, try posting your question on the Python Windows API
mailing list.

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

You may be able to use WMI (via Python) to accomplish what you're trying
to do.

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


Re: [Tutor] Cross-Module Interaction

2011-02-26 Thread Walter Prins
On 26 February 2011 11:10, Corey Richardson kb1...@aim.com wrote:

 On 02/26/2011 06:05 AM, Walter Prins wrote:
  I'd be tempted to say you should not be worrying about such performance
  issues at this stage.

 Indeed, but I can't have every piece of variable information being saved
 to disk and then read back again every time a player leaves or enters a
 room, that'd just be silly!


Sure.  I still think however that at this stage it's a much of a muchness.
Modern PC's and disk caching subsystems being what they are, you likely
won't really notice it either way until you're quite far along with this
project.  ;)  (I'm not suggesting you should be willfully stupid of course,
and the mere fact that you write the above indicates you're not, so there's
no problem!)


 Playing MUD's for a bit it gets annoying on a medium-size server when
 you have to wait more than 3 seconds just to get how much health you
 have after attacking some baddie. I won't be trying to pull every
 microsecond of efficiency out of this, but I would like it to be
 sensible and now waste time dawdling.


Sure.  It's of course an assumption that the delay you see is due to disk
I/O... (it may well be, but then again there's lots of possible reasons for
things being slow...)



 (And the full quote is We should forget about *small* efficiencies, say
 about 97% of the time: premature optimization is the root of all evil.
 (emphasis added))


I know what the full quote is, I continue to be of the opinion that the
point it makes is relevant, it's not worth worrying too much about.  Pick a
strategy that works sufficiently, you can always refactor and improve when
needed.

Good luck,

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


Re: [Tutor] Running Existing Python

2011-02-26 Thread Steven D'Aprano

Justin Bonnell wrote:

Okay. When I try to run the script from the terminal, it still doesn't work. 
Here is a screenshot.


Please don't send screenshots except as a last resort. Just copy and 
paste the error message -- it is ordinary text in a terminal window.


The error seems pretty straight-forward: it says no such file or 
directory. You're telling Python to run the file hello.py in the 
current directory. There obviously is no such file -- either you got the 
name wrong (perhaps it is Hello.py?) or it is in another directory.




--
Steven

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


Re: [Tutor] accessing another system's environment

2011-02-26 Thread Walter Prins
On 26 February 2011 04:26, Bill Allen walle...@gmail.com wrote:

 Yes, that's it exactly.:-)

 I administrate the workstations in our engineering environment and some of
 the major pieces of software we use are configured via the Windows system
 environment variables.  Being able to reach out to a PC and check or change
 those is handy, even important, in my situation.   I am trying to explore
 the possibility of managing these from a system I am using in a platform
 independent way and figure that I ought to be able to do this with Python.
 Perhaps there are third party Python modules I need to help accomplish this?


Are you intending changing *running processes* environment variables, or
merely update a given PC's configuration so that next time an app starts
they'll see the new settings?  (I'd guess the latter as even Windows itself
won't e.g. update running instances of cmd.exe's environment when you change
them after an instance of cmd.exe has started.)

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


Re: [Tutor] accessing another system's environment

2011-02-26 Thread Dave Angel

On 01/-10/-28163 02:59 PM, Steve Willoughby wrote:

On 26-Feb-11 01:19, ALAN GAULD wrote:

Bill,

That's the same thing we are talking about.
The problem is those environment variables are
highly variable so you can't talk about a machine's environment.
Two users on the same machine (at the same time) may have
very different environments. And a batch file or program can


I'm a Unix hacker, so forgive me if my understanding of Windows is a bit
naive. I think, though, that Windows has a set of environment variables
which are system-wide, added automatically to the user set of variables
when a new process is launched. Yes, they can be changed or deleted but
there is a standard set applied to all users.

If that's a correct assumption on my part, there must be somewhere that
can be read from, probably (I would guess) in the registry. So a script
which could read/write those registry keys may do what is required here.

The issue of exposing that to remote machines remains a dangling issue,
though.

Of course, it's not entirely clear we're solving a Python question,
although this discussion may well go more solidly into that space.



Indeed.  in Windows, there are two sets of registry keys for environment 
variables, one is system wide, and one is per user.  When Explorer 
launches a console or an application for a particular user, it combines 
those two sets of keys to come up with an initial set of environment 
variables.


I tried to launch a VirtualBox XP machine, but it failed for some 
reason.  Probably I have too much else running.  So I can't tell you the 
key names.


I'd suggest asking about remotely accessing the registry on the 
python-win32 forum.  I'm sure the win32 extension have a way, I just 
don't know if it'll work from a Linux client.


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


Re: [Tutor] accessing another system's environment

2011-02-26 Thread David
On 26 February 2011 22:42, Walter Prins wpr...@gmail.com wrote:

 On 26 February 2011 04:26, Bill Allen walle...@gmail.com wrote:

 I administrate the workstations in our engineering environment and some of
 the major pieces of software we use are configured via the Windows system
 environment variables.  Being able to reach out to a PC and check or change
 those is handy, even important, in my situation.   I am trying to explore
 the possibility of managing these from a system I am using in a platform
 independent way and figure that I ought to be able to do this with Python.
 Perhaps there are third party Python modules I need to help accomplish this?

 Are you intending changing *running processes* environment variables, or
 merely update a given PC's configuration so that next time an app starts
 they'll see the new settings?  (I'd guess the latter as even Windows itself
 won't e.g. update running instances of cmd.exe's environment when you change
 them after an instance of cmd.exe has started.)

Indeed. check is easy by my method. change is harder.
I can only guess this would involve somehow editing the windows registry.
I have nothing to offer on that topic.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] accessing another system's environment

2011-02-26 Thread Modulok
I'm coming into this thread late so I might be off the mark here, but
it seems like you're going about it backwards:

Instead of trying to reach in and modify a user's environment, which
is highly variable and process dependent, why not just wrap the
software they're running? Have a python script wrap all of the
programs you're trying to configure on the client's machine. (No
matter how you do it, you'd have to install a client program of some
kind anyway.) When they launch the 'program' in question, they're
really launching a python script. The script checks in with a remote
server that holds the config files or environment data. (Or whatever
else you need.) The client script says some thing like I'm john,
running program version x.x. Give me my env variables.)

The server then replies with any variables that the client needs to
set and their values. You could do this with a python script running
on a server sending ajax responses. (There's an ajax module in the
standard library.) The wrapper, running on the client gets the
response and set any environment variables for the process it's about
to launch. It then starts the real program, passing the properly
configured environment on to it.

You have to write two programs. 1. A client wrapper that asks the
server for its data and 2. A simple server that passes any data back
to the client.

In effect, you'll be able to change the clients configuration,
environment variables or *anything else* that needs done before your
script launches the the real client program. You don't have to deal
with screwing around with the client's environment or the complexities
that brings up either.


On 2/26/11, Dave Angel da...@ieee.org wrote:
 On 01/-10/-28163 02:59 PM, Steve Willoughby wrote:
 On 26-Feb-11 01:19, ALAN GAULD wrote:
 Bill,

 That's the same thing we are talking about.
 The problem is those environment variables are
 highly variable so you can't talk about a machine's environment.
 Two users on the same machine (at the same time) may have
 very different environments. And a batch file or program can

 I'm a Unix hacker, so forgive me if my understanding of Windows is a bit
 naive. I think, though, that Windows has a set of environment variables
 which are system-wide, added automatically to the user set of variables
 when a new process is launched. Yes, they can be changed or deleted but
 there is a standard set applied to all users.

 If that's a correct assumption on my part, there must be somewhere that
 can be read from, probably (I would guess) in the registry. So a script
 which could read/write those registry keys may do what is required here.

 The issue of exposing that to remote machines remains a dangling issue,
 though.

 Of course, it's not entirely clear we're solving a Python question,
 although this discussion may well go more solidly into that space.


 Indeed.  in Windows, there are two sets of registry keys for environment
 variables, one is system wide, and one is per user.  When Explorer
 launches a console or an application for a particular user, it combines
 those two sets of keys to come up with an initial set of environment
 variables.

 I tried to launch a VirtualBox XP machine, but it failed for some
 reason.  Probably I have too much else running.  So I can't tell you the
 key names.

 I'd suggest asking about remotely accessing the registry on the
 python-win32 forum.  I'm sure the win32 extension have a way, I just
 don't know if it'll work from a Linux client.

 DaveA
 ___
 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] accessing another system's environment

2011-02-26 Thread Modulok
On 2/26/11, Modulok modu...@gmail.com wrote:
...
 The server then replies with any variables that the client needs to
 set and their values. You could do this with a python script running
 on a server sending ajax responses. (There's an ajax module in the
 standard library.)
...

Sorry, I meant a 'json' module, not 'ajax'. I've been doing too much
web programming recently :p. You could probably even get away with not
having to write a server, just set up a web server to handle it,
sending a well-formed response.

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


Re: [Tutor] accessing another system's environment

2011-02-26 Thread Bill Allen
Wow!   What an overwhelming response to my inquiry.   All the post have been
very informative and have given me plenty to consider.   I can see now this
is a win32 api question, not really Python.   There has been more than
enough here to point to some resources for win32 api and I have found
library resources for that for Python, so I think I am on my way.  It is
just a matter of finding the right win32 api calls to do what I am wanting
to do.


Thanks again everyone, this was a great help to me.


-Bill








On Wed, Feb 23, 2011 at 21:53, Bill Allen walle...@gmail.com wrote:


 I know that I can use the following to get a listing of the environment of
 my own system.   How can I do similar for another system on my network.
 This is for administrative purposes.

  import os
  for param in os.environ.keys():
 print(param, os.environ[param])

 --Bill







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


[Tutor] Object, methods, class

2011-02-26 Thread Christopher Brookes
Hi,
Is there in Python private/protected attributes in class like in other
langage ?

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


Re: [Tutor] Object, methods, class

2011-02-26 Thread Knacktus

Am 26.02.2011 18:49, schrieb Christopher Brookes:

Hi,
Is there in Python private/protected attributes in class like in other
langage ?

Yes, there is. But it's protected by convention not compiler ;-).
Check out this:
http://docs.python.org/tutorial/classes.html#private-variables


--
Brookes Christopher.



___
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] Running Existing Python

2011-02-26 Thread Justin Bonnell

On Feb 26, 2011, at 4:49 AM, Dave Angel wrote:

 On 01/-10/-28163 02:59 PM, Justin Bonnell wrote:
 Okay. When I try to run the script from the terminal, it still doesn't work. 
 Here is a screenshot.
 
 
 
 
 
 What am I doing wrong?
 
 1) You're top-posting.  Put your responses after the quote you're responding 
 to.
--Okay. I'm pretty new to this so most of my responses were just general 
questions rather than specific responses.
 
 2) You're trying to include graphical images in a text-based newsgroup.  Just 
 use copy/paste, and include it in your message.
--Got it. I will do that from now on. 

 
 3) You don't tell us where the hello.py file actually is.  Presumably it's 
 not in the current directory when you run that.  Two cures for that:  either 
 specify its real location,
 python   ~/mysources/hello.py

--This is the location of the file:

/jwbonnell/bin/Python 2.7/Extras/Demo/tkinter/guido/hello.py

but it still says it cannot find the directory when I try to run it or cd to 
it. Is there any way that I can tell which directory the shell is currently 
working from?

 or cd to the proper directory.  The latter is usually easier, but it depends 
 where other files your script are located.
 
 DaveA

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


Re: [Tutor] Running Existing Python

2011-02-26 Thread Corey Richardson
On 02/26/2011 04:10 PM, Justin Bonnell wrote:

 --This is the location of the file:
 
   /jwbonnell/bin/Python 2.7/Extras/Demo/tkinter/guido/hello.py
 
 but it still says it cannot find the directory when I try to run it or cd to 
 it. Is there any way that I can tell which directory the shell is currently 
 working from?

At the terminal, the command pwd , print working directory, should do
the trick.

If you cannot cd to the directory, that's generally a pretty big hint
that the directory doesn't exist ;-)

But yet you can see it in your file browser? That's most curious.

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


Re: [Tutor] Running Existing Python

2011-02-26 Thread Justin Bonnell

On Feb 26, 2011, at 3:29 AM, Alan Gauld wrote:

This is really helpful directions and I am trying to follow what you're saying. 
I think you are getting my response to another person helping me so this will 
basically repeat what I was saying there. I am really new to this and am trying 
to learn on my own so thanks for your help and patience. 

 The error says it can't find the file hello.py.
 That means its probably in some other folder 
 or you need to specify the full or relative path to the file
 This is a MacOS issue not Python, its how your MacOS 
 shell is searching for the file.
 
 If it is in the same folder try explicitly telling MacOS:
 
 $ python ./hello.py
 
 Or if it is somewhere else either cd to that folder 
 or type the path:
 
 $ python /the/full/path/to/the/dfile/hello.py

--I tried to follow this using:
/jwbonnell/bin/Python 2.7/Extras/Demo/tkinter/guido/hello.py
which is the correct location of the hello.py file.

 
 There are some environment variables you can 
 set in your login script which will help MacOS 
 find the files but they depend on which shell 
 Terminal is running, tcsh or bash are the usual 
 options.
--My Terminal is running bash. 

 
 Finally there is a trick you can use on the hello.py 
 file that means you can launch the .py file directly 
 from Finder. It's called the shebang trick by Unix 
 folks.
 
 Basically you add a line like
 
 #! /usr/env/python
 
 To the very top of the file. MacOS will then use that 
 command to execute the script. If usr/env doesn't 
 work type
--So if I add that line to the file, then I use 
$ python /usr/env/python ?

 
 $ which python
--This is the correct for my computer:

/Library/Frameworks/Python.framework/Versions/2.7/bin/python

 
 and copy the output instead of /usr/env
 
 
 Alan Gauld
 Author of the Learn To Program website
 http://www.alan-g.me.uk/
 
 
 
 
 - Original Message 
 From: Justin Bonnell jwbonne...@gmail.com
 To: Alan Gauld alan.ga...@btinternet.com
 Cc: tutor@python.org
 Sent: Saturday, 26 February, 2011 6:49:37
 Subject: Re: [Tutor] Running Existing Python
 
 Okay. When I try to run the script from the terminal, it still doesn't work. 
  
 Here is a screenshot.
 
 
 What am I doing wrong?
 
 
 On Feb 25,  2011, at 6:46 PM, Alan Gauld wrote:
 
 
 Justin Bonnell jwbonne...@gmail.com wrote
 
 Python 2.7.1 (r271:86882M, Nov 30 2010, 10:35:34) [GCC 4.2.1 (Apple  Inc. 
 build 5664)] on darwin
 Type copyright, credits or  license() for more information.
 
 The  prompt means  you are already inside Python.
 You can type Python commands at the   prompt, things like
 
 print  Hello
 
 But you cannot ruin a program from inside the   prompt (well, you can, 
 but 
 its more complicated than sane people  want to bother with! :-)
 
 You run a Python script from the OS  Terminal prompt:
 
 $ python hello.py
 
 Shouldn't I be able to run hello.py from the IDLE interpreter?
 
 You can't run it from the  prompt in IDLE but
 What you  can do is open the file for editing and then run that file using 
 the menu  commands, then the output will show up in the interpreter window.
 
 I  get how to do this now^^
 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
 
 

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


Re: [Tutor] Running Existing Python

2011-02-26 Thread शंतनू

On 27-Feb-2011, at 2:40 AM, Justin Bonnell wrote:

 On Feb 26, 2011, at 4:49 AM, Dave Angel wrote:
 3) You don't tell us where the hello.py file actually is.  Presumably it's 
 not in the current directory when you run that.  Two cures for that:  either 
 specify its real location,
 python   ~/mysources/hello.py
 
 --This is the location of the file:
 
   /jwbonnell/bin/Python 2.7/Extras/Demo/tkinter/guido/hello.py

You need to escape space.

Try

/jwbonnell/bin/Python\ 2.7/Extras/Demo/tkinter/guido/hello.py


There is '\' before space.

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


Re: [Tutor] Running Existing Python

2011-02-26 Thread Dave Angel

On 02/26/2011 04:10 PM, Justin Bonnell wrote:


On Feb 26, 2011, at 4:49 AM, Dave Angel wrote:


On 01/-10/-28163 02:59 PM, Justin Bonnell wrote:

Okay. When I try to run the script from the terminal, it still doesn't work. 
Here is a screenshot.





What am I doing wrong?


1) You're top-posting.  Put your responses after the quote you're responding to.

--Okay. I'm pretty new to this so most of my responses were just general 
questions rather than specific responses.


2) You're trying to include graphical images in a text-based newsgroup.  Just 
use copy/paste, and include it in your message.

--Got it. I will do that from now on.



3) You don't tell us where the hello.py file actually is.  Presumably it's not 
in the current directory when you run that.  Two cures for that:  either 
specify its real location,
 python   ~/mysources/hello.py


--This is the location of the file:

/jwbonnell/bin/Python 2.7/Extras/Demo/tkinter/guido/hello.py

but it still says it cannot find the directory when I try to run it or cd to 
it. Is there any way that I can tell which directory the shell is currently 
working from?



pwd will show your current directory on Linux.  And it's usually showing 
in your prompt.


As for cd not working, someone else has pointed out that in the shell, 
you need to escape certain characters, the space being one.  I try to 
avoid ever having spaces in directory or file names.



or cd to the proper directory.  The latter is usually easier, but it depends 
where other files your script are located.

DaveA





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


Re: [Tutor] Running Existing Python

2011-02-26 Thread Walter Prins
On 26 February 2011 21:18, Justin Bonnell jwbonne...@gmail.com wrote:

 --I tried to follow this using:
 /jwbonnell/bin/Python 2.7/Extras/Demo/tkinter/guido/hello.py
 which is the correct location of the hello.py file.


Try putting quotes around the full path. The problem is that the space
between Python and 2.7 makes the line look like 2 arguments, e.g.
 /jwbonnell/bin/Python
... and ...
2.7/Extras/Demo/tkinter/guido/hello.py

If you double quote the entire string like so:
/jwbonnell/bin/Python 2.7/Extras/Demo/tkinter/guido/hello.py

By quoting the line you're telling the system not to interpret that space
and make it part of the argument to the Python interpreter.  (Aside: You
would need to quote the path also when using it with the cd command, as
the same problem will happen unless you quote it.)

The other thing I'd suggest is to just use IDLE which may be slightly easier
at this point.  In the main IDLE shell, click File-Open, open the file
(it opens in its own window) then run it from there using e.g. F5.  The
output appears in the IDLE shell then.

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


Re: [Tutor] Running Existing Python

2011-02-26 Thread Steven D'Aprano

Justin Bonnell wrote:


--This is the location of the file:

/jwbonnell/bin/Python 2.7/Extras/Demo/tkinter/guido/hello.py



I doubt that. Mac OS is a type of Unix, and it would shock me if it puts 
home directories (the jwbonnell/ part) directly under the file system 
root /



My guess is that the correct path is probably

/home/jwbonnell/bin/Python 2.7/Extras/Demo/tkinter/guido/hello.py

but of course I could be wrong. Don't forget to quote the path, 
otherwise the spaces will mess things up for you:


/home/jwbonnell/bin/Python 2.7/Extras/Demo/tkinter/guido/hello.py

Try running this command from your command prompt:

locate hello.py

and see if it gives anything useful. (I don't know if OS X comes with 
locate as standard, so don't be surprised if you get an error.)


Another alternative would be to refer to the file using:

python ~/bin/Python 2.7/Extras/Demo/tkinter/guido/hello.py

Note that you don't quote the tilde ~ at the start.



--
Steven

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


Re: [Tutor] Running Existing Python

2011-02-26 Thread Justin Bonnell

On Feb 26, 2011, at 3:18 PM, Corey Richardson wrote:

 On 02/26/2011 04:10 PM, Justin Bonnell wrote:
 
 --This is the location of the file:
 
  /jwbonnell/bin/Python 2.7/Extras/Demo/tkinter/guido/hello.py
 
 but it still says it cannot find the directory when I try to run it or cd to 
 it. Is there any way that I can tell which directory the shell is currently 
 working from?
 
 At the terminal, the command pwd , print working directory, should do
 the trick.
 
 If you cannot cd to the directory, that's generally a pretty big hint
 that the directory doesn't exist ;-)
 
 But yet you can see it in your file browser? That's most curious.

--My current working directory is not what I have been trying to cd to, so I'm 
assuming that I am using the cd command wrong. 

I have tried:

$ cd /jwbonnell/bin/Python\2.7/Extras/Demo/tkinter/guido
$ cd /jwbonnell/bin/Python\2.7/Extras/Demo/tkinter/guido/hello.py
$ cd /jwbonnell/bin/Python 2.7/Extras/Demo/tkinter/guido/hello.py

 
 -- 
 Corey Richardson
 ___
 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] Running Existing Python

2011-02-26 Thread Corey Richardson
On 02/26/2011 04:32 PM, Justin Bonnell wrote:
 --My current working directory is not what I have been trying to cd to, so 
 I'm assuming that I am using the cd command wrong. 
 
 I have tried:
 
 $ cd /jwbonnell/bin/Python\2.7/Extras/Demo/tkinter/guido
 $ cd /jwbonnell/bin/Python\2.7/Extras/Demo/tkinter/guido/hello.py
 $ cd /jwbonnell/bin/Python 2.7/Extras/Demo/tkinter/guido/hello.py
 

Alas, you still do it wrong. You don't just replace the space with a
backslash, you put a slash _before_ the space. Or like Steven (I think
it was) suggested, put it in quotes.



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


Re: [Tutor] Object, methods, class

2011-02-26 Thread Steven D'Aprano

Christopher Brookes wrote:

Hi,
Is there in Python private/protected attributes in class like in other
langage ?



There's a short answer, a long answer, and an even longer answer.

The short answer is No.

The long answer is, not exactly. Python has private names, but they are 
not enforced by the compiler, but only by naming convention: use names 
starting with a single underscore to mean private:


_private_variable = 42

Anybody using such private names will know that they have nobody to 
blame but themselves if things break.


Inside classes (but not outside), there is a second convention which is 
enforced by the compiler: name mangling. If you define this:


class K:
_a = 23
__b = 42  # TWO leading underscores


the _a attribute is private by convention, but the __b attribute has its 
name mangled by the compiler to:


_K__b


This is to prevent *accidental* clashes when writing subclasses, but of 
course it can't prevent deliberate access. Since you know the name of 
the class, it's easy to do your own mangling and get access to the 
private attribute.


(For extra bonus points, can you see which circumstances namespace 
mangling will fail to prevent accidental name clashes?)



You might be thinking that double-underscore names are stronger, and 
therefore safer, than single-underscore. No. In my opinion, don't waste 
your time and energy with double-underscore names.


There's one further naming convention that is relevant: names with 
double leading and trailing underscores. These names are reserved for 
Python, and are used for special methods like __init__ __getitem__ 
__enter__ etc.



The even longer answer is, no, and thank goodness for that, because 
having the compiler enforce private attributes is a real pain! It gets 
in the way of testing and debugging, and testing is MUCH more important 
than private or protected.


It does very little good, and lots of harm, and gets in the way of 
things that you need. The internet is full of people asking how do I 
access private members and similar questions. They're not asking it to 
be difficult, but because they need to. It is a *good* thing that Python 
makes it a convention.


In every language that I know of, it is possible to bypass the 
compiler's protection of private and protected attributes:


E.g. in Ruby:
http://blog.confabulus.com/2008/10/26/testing-protected-and-private-methods-in-ruby/
http://www.skorks.com/2010/04/ruby-access-control-are-private-and-protected-methods-only-a-guideline/

In C++:
http://www.gotw.ca/gotw/076.htm
http://stackoverflow.com/questions/729363/is-it-possible-to-access-private-members-of-a-class

Java:
http://stackoverflow.com/questions/1306166/how-can-i-access-private-class-members-in-java


Python takes another approach. Instead of putting up barriers to the 
caller that must be overcome, barriers that just get in the way of 
debugging and testing, Python doesn't waste it's time trying to enforce 
something that people will find a way to break. Instead Python takes the 
attitude we're all adults here. It trusts you not to access private 
attributes and methods unless you really need to, and to take the 
consequences if you do.


(The only exception is that protection of objects written in C is 
treated more strongly, because that could cause a core dump and 
potential memory corruption, not just a safe Python exception. But even 
there, using the new ctypes module, you can do some pretty scary things.)




--
Steven

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


Re: [Tutor] Running Existing Python

2011-02-26 Thread Steven D'Aprano

Justin Bonnell wrote:

--My current working directory is not what I have been trying to cd to, so I'm assuming that I am using the cd command wrong. 



You don't need to cd into the current working directory. You're already 
there. That's what working directory means -- the directory you just 
cd'ed into.


But you can if you like. That's just:

cd .

Dot always means this directory, no matter where you are.



I have tried:

$ cd /jwbonnell/bin/Python\2.7/Extras/Demo/tkinter/guido


And what happened?

Please run these two lines and copy and paste the results back to us:


ls -ld /jwbonnell
ls -ld /home/jwbonnell





$ cd /jwbonnell/bin/Python\2.7/Extras/Demo/tkinter/guido/hello.py
$ cd /jwbonnell/bin/Python 2.7/Extras/Demo/tkinter/guido/hello.py


cd stands for Change Directory. You can't cd into a file.


--
Steven

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


Re: [Tutor] Running Existing Python

2011-02-26 Thread ALAN GAULD


--This is the location of the file:


/jwbonnell/bin/Python 2.7/Extras/Demo/tkinter/guido/hello.py


but it still says it cannot find the directory when I try to run it or cd to 
it. 

As an obvious beginner with the shell the easiest way to change folder 
is MacOS is to use the Finder. type cd at the prrompt then locate the 
folder in Finder and drag it to the Terminal window. That should cause 
the Terminal to change to that folder


The other thing to do is to let the shell copmplete the name for you, 
thus type

cd /jwbtab

and the shell will complete the first folder for you, then type bitab 
to complete bin and so on. That will ensure the spaces are handled 
correctly.

HTH,

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


Re: [Tutor] Object, methods, class

2011-02-26 Thread Alan Gauld


Christopher Brookes chris.klai...@gmail.com wrote

Is there in Python private/protected attributes in class like in 
other

langage ?


Steven has given you a comprehensive answer but as a bit of
history none of the early OOP languages used public/protected/private
etc. They either made all variables private (Smalltalk) or public
(Object Pascal and Simula(I think) ).

It was really C++ that started the vogue for mixing and matching
the styles. Even it didn't introduce protected until version 1.2 of
the language and Stroustrup admits to having concerns and
doubts about the wisdom of the decision. But several other
languages (Java, Object Pascal(aka Delphi) ) have followed
C++ down that route.

Python just asks users to be sensible, it doesn't attempt
to protect(excuse the pun) them from themselves!

Just musing

--
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


[Tutor] python module to search a website

2011-02-26 Thread vineeth

Hello all,

I am looking forward for a python module to search a website and extract 
the url.


For example I found a module for Amazon with the name amazonproduct, 
the api does the job of extracting the data based on the query it even 
parses the url data. I am looking some more similar query search python 
module for other websites like Amazon.


Any help is appreciated.

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


Re: [Tutor] python module to search a website

2011-02-26 Thread Corey Richardson
On 02/26/2011 10:11 PM, vineeth wrote:
 Hello all,
 
 I am looking forward for a python module to search a website and extract 
 the url.

What website, what is it searching for, and what URL is it looking for?

 
 For example I found a module for Amazon with the name amazonproduct, 
 the api does the job of extracting the data based on the query it even 
 parses the url data. I am looking some more similar query search python 
 module for other websites like Amazon.

The only module I found for amazon-product was a python interface to
Amazon's advertising API. What data does it extract, what query, and
which URL does it parse? From what I found that module uses the API to
search the website, a service provided by Amazon and not something
Python is doing itself.

You may want to look into urlparse and urllib2, for parsing URLs and
opening websites respectively.

http://docs.python.org/library/urlparse.html
http://docs.python.org/library/urllib2.html

If that isn't what you're looking for, you'll need to be a bit more
descriptive.

If you are going to be parsing the HTML and then searching for specific
elements you might look into BeautifulSoup.

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


Re: [Tutor] python module to search a website

2011-02-26 Thread Bill Allen
n Sat, Feb 26, 2011 at 21:11, vineeth vineethrak...@gmail.com wrote:

 Hello all,

 I am looking forward for a python module to search a website and extract
 the url.

 For example I found a module for Amazon with the name amazonproduct, the
 api does the job of extracting the data based on the query it even parses
 the url data. I am looking some more similar query search python module for
 other websites like Amazon.

 Any help is appreciated.

 Thank You
 Vin

I am not sure what url you are trying to extract, or from where, but I can
give you an example of basic web scraping if that is your aim.

The following works for Python 2.x.

#This one module that gives you the needed methods to read the html from a
webpage
import urllib

#set a variable to the needed website
mypath = http://some_website.com;

#read all the html data from the page into a variable and then parse through
it looking for urls
mylines = urllib.urlopen(mypath).readlines()
for item in mylines:
if http://; in item:
 ...do something with the url that was found in the page html...
 ...etc...


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


Re: [Tutor] Object, methods, class

2011-02-26 Thread Knacktus

Once again a very insightfull answer. Much appreciated! Same to you, Alan.
I paricularly like the even longer answer. It remindes us of how lucky 
we are using Python and brings me light in dark times when I wish I had 
better code completion in my IDE for my own spaghetti-code ;-))

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


Re: [Tutor] python module to search a website

2011-02-26 Thread vineeth

Hi Bill,

Thanks for the reply, I know how the urllib module works I am not 
looking for scraping. I am looking to obtain the html page that my query 
is going to return. Just like when you type in a site like Amazon you 
get a bunch of product listing the module has to search the website and 
return the html link. I can ofcourse scrap the information from that link.


Thanks
Vin

On 02/27/2011 12:04 AM, Bill Allen wrote:
n Sat, Feb 26, 2011 at 21:11, vineeth vineethrak...@gmail.com 
mailto:vineethrak...@gmail.com wrote:


Hello all,

I am looking forward for a python module to search a website and
extract the url.

For example I found a module for Amazon with the name
amazonproduct, the api does the job of extracting the data based
on the query it even parses the url data. I am looking some more
similar query search python module for other websites like Amazon.

Any help is appreciated.

Thank You
Vin

I am not sure what url you are trying to extract, or from where, but I 
can give you an example of basic web scraping if that is your aim.


The following works for Python 2.x.

#This one module that gives you the needed methods to read the html 
from a webpage

import urllib

#set a variable to the needed website
mypath = http://some_website.com;

#read all the html data from the page into a variable and then parse 
through it looking for urls

mylines = urllib.urlopen(mypath).readlines()
for item in mylines:
if http://; in item:
 ...do something with the url that was found in the page html...
 ...etc...


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