Newbie questions for Python usage

2006-08-22 Thread Caolan
Hello,
 
I am fairly new to Python and after exploring the 
language some I have some questions:
 


  I understand HOW to 
  use the lambda operator, but WHY would you want to use it? Can anyone please 
  give an example of WHY you would need it as opposed to just declaring a 
  function either in the local scope, or outside? 
  I would like to be 
  able to declare as a member attribute a file object, however because there is 
  no declaration of variable types like there is in C++, there doesn’t seem to 
  be a way to do this without first making a fobj = open(…) call. Is this 
  true?
  Now for an os 
  import question for Windows. I wish to automate the builds of VS.NET 2005 and 
  I can do so by executing the os.system(...) command however I cannot see how 
  to execute the vcvars32.cmd first to set environment variables and then 
  execute the actual command-line for the build itself.

Thanks for the help all!
Caolan-- 
http://mail.python.org/mailman/listinfo/python-list

RE: Newbie questions for Python usage

2006-08-22 Thread Caolan
Title: Re: Newbie questions for Python usage






Thanks 
Fred.
> just assign to the attribute and be done 
with>  it.  if you want to use a placeholder value, use 
None:
 
I thought I had tried that already but got an error. 
I'll try it again, and as for the 2nd one, I was hoping to avoid the usage of 
.cmd or .bat files altogether. Thanks!
 
-Caolan O'Domhnaill




From: 
[EMAIL PROTECTED] on behalf of Fredrik 
LundhSent: Tue 8/22/2006 4:08 PMTo: 
python-list@python.orgSubject: Re: Newbie questions for Python 
usage

Caolan wrote:>    1. I understand HOW 
to use the lambda operator, but WHY would 
you>   want to use it? Can anyone 
please give an example of WHY you 
would>   need it as opposed to just 
declaring a function either in the>   
local scope, or outside?you don't *need* it, 
because callback = lambda arg: 
_expression_is, for most practical purposes, the same thing 
as def 
callback(arg): return 
_expression_(the only difference is that the __name__ attribute for the 
functionobjects will differ; all lambdas are named "", while 
objectscreated by "def" have the original name.)however, in some 
cases, it's may be convenient to use the lambda form,for stylistic 
reasons.>    2. I would like to be able to declare as 
a member attribute a file>   object, 
however because there is no declaration of variable 
types>   like there is in C++, there 
doesn’t seem to be a way to do this>   
without first making a fobj = open(…) call. Is this true?not sure what 
you mean, really -- attributes are not typed, and there'sno way to "declare" 
them.  just assign to the attribute and be done withit.  if you 
want to use a placeholder value, use None: class 
foo: def 
__init__(self): 
self.file = None # not opened 
yet def open(self, 
name): 
self.file = open(name)or class 
foo: file = None # shared 
placeholder def 
__init__(self): 
pass def open(self, 
name): 
self.file = open(name)> Now for an os import question for Windows. I 
wish to automate the> builds of VS.NET 2005 and I can do so by executing 
the os.system(...)> command however I cannot see how to execute the 
vcvars32.cmd first to> set environment variables and then execute the 
actual command-line for> the build itself.there's no easy way to 
do that: environment variables set by a sub-process isn't available to the 
main process.the easiest way to do this might be to simply generate a 
short temporaryBAT-file for each command, and do os.system() on that 
file: f = open("temp.bat", 
"w") f.write("@call 
vcvars32.bat\n") f.write("cl 
...\n") f.close() 
os.system(f.name) 
os.remove(f.name)--http://mail.python.org/mailman/listinfo/python-list


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

RE: in-memory-only file object from string

2006-08-23 Thread Caolan
Title: in-memory-only file object from string






The mmap module should do 
what you are looking for. It allows you to store data in memory (hence the name 
memory map) and treat it as both a string and a file.


From: 
[EMAIL PROTECTED] on behalf of 
bobrikSent: Wed 8/23/2006 2:56 PMTo: 
python-list@python.orgSubject: in-memory-only file object from 
string

Hello,how to create a file object whose contents I 
initialize from a stringand which is purely in memory?I can make a 
workaround like this:filecontents = "Very interesting stuff ... 
"file = os.tmpfile ()file.write (filecontents)file.seek 
(0)procedure (fileobject = file)but this creates a file on harddisk. 
Instead I would like to usesomething like:filecontents = "Very 
interesting stuff ... "file = stringfile (filecontents)procedure 
(fileobject = file)Is this possible somehow? I appreciate any 
help.--http://mail.python.org/mailman/listinfo/python-list


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

RE: Best Editor

2006-08-24 Thread Caolan
Title: Re: Best Editor






I like ActiveState's KOMODO 
editor. It is multilanguage compiler editor. Its not free but it is inexpensive 
for what it does, IMO. I believe they have a 30day free trial and a version for 
both platforms you mentioned.
 
-Caolan.


From: 
[EMAIL PROTECTED] on behalf of Michiel 
SikmaSent: Thu 8/24/2006 4:41 AMTo: JAG CHANCc: 
python-list@python.orgSubject: Re: Best Editor

I personally use Eclipse with PyDev. It is a cross-platform 
solution because Eclipse is made with Java.http://www.eclipse.org/http://pydev.sourceforge.net/MichielOp 
24-aug-2006, om 13:29 heeft JAG CHAN het volgende geschreven:> 
Friends, I am trying to learn Python.> It will be of great help to me if 
you let me know which one would > be best> editor for 
learning Python.> Plese note that I would like to have multiplatform 
editor which > will be> useful for both LInux and Windows 
XP.> Thanks.> --> http://mail.python.org/mailman/listinfo/python-list--http://mail.python.org/mailman/listinfo/python-list


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

How to include and use a .NET DLL and namespace.

2006-08-31 Thread Caolan
Hello,
 
I am in need of importing in a .NET namespace from 
a built DLL. How do I get Python to pickup and recognise the namespace and 
classes in the DLL?
 
Thanks,
 
Caolan O'Domhnaill-- 
http://mail.python.org/mailman/listinfo/python-list

Newbie question involving buffered input

2006-09-01 Thread Caolan

I am executing 
the code below on a Windows XP system and if I enter > 2 characters it 
buffers the input and the call to sys.stdin.flush does not flush the input, it 
remains buffered.
 
What am I doing wrong here?
 
Thanks,
 
Caolan
 
    
try:    
gooberselectX = sys.stdin.read(2)    
except IOError, 
e:    print 
'error reading from stdin device'    
except KeyboardInterrupt, 
e:    print 
'you cannot break. please use the \'q\' key to 
exit'    
else:    
try:    
sys.stdin.flush()    
except IOError, 
e:    
print 'error flushing buffered input'-- 
http://mail.python.org/mailman/listinfo/python-list

RE: Newbie question involving buffered input

2006-09-01 Thread Caolan
Title: Re: Newbie question involving buffered input






That makes sense I suppose - 
why is there a stdin.flush() method then?


From: 
[EMAIL PROTECTED] on behalf of Jean-Paul 
CalderoneSent: Fri 9/1/2006 9:53 AMTo: 
python-list@python.orgSubject: Re: Newbie question involving buffered 
input

On Fri, 1 Sep 2006 09:31:11 -0700, Caolan 
<[EMAIL PROTECTED]> wrote:>I am executing the code below on a Windows 
XP system and if I enter > 2 characters it buffers the input and the call to 
sys.stdin.flush does not flush the input, it remains buffered.You cannot 
flush input.  The flush method only relates to output.  The*other* 
side of the file has to flush *its* output in order for you tosee it as 
input.On Linux, the termios module provides a way to tell the system not 
to doany buffering on a file descriptor.  pywin32 may expose 
equivalentfunctionality for Windows.Jean-Paul--http://mail.python.org/mailman/listinfo/python-list


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