Re: [Tutor] Possible to search text file for multiple string values at once?
Le Fri, 23 Jan 2009 14:45:32 -0600, W W a écrit : > On Fri, Jan 23, 2009 at 1:11 PM, Scott Stueben wrote: > > > Thanks for the help so far - it seems easy enough. To clarify on the > > points you have asked me about: > > > > A sqlite3 database on my machine would be an excellent idea for > > personal use. I would like to be able to get a functional script for > > others on my team to use, so maybe a script or compiled program > > (Win32) eventually. > > > As long as everyone on your team has python installed (or as long as python > is installed on the machines they'll be using), a functional script would be > fairly easy to get rolling. Sqlite is (AFAIK) included with the newer > versions of python by default. Heck, it's on the version I have installed on > my phone! (Cingular 8525). Simply zipping up the directory should provide an > easy enough distribution method. Although, you *could* even write a python > script that does the "install" for them. > > > > As for output, I would probably like to return the entire lines that > > contain any search results of those strings. Maybe just output to a > > results.txt that would have the entire line of each line that contains > > 'Bob', 'John', 'Joe', 'Jim', and or 'Fred'. > > > The simplest method: > > In [5]: f = open('interculturalinterview2.txt', 'r') > > In [6]: searchstrings = ('holy', 'hand', 'grenade', 'potato') > > In [7]: for line in f.readlines(): >...: for word in searchstrings: >...: if word in line: >...: print line >...: >...: > Hana: have a bonfire n candy apples n make potatoes on a car lol! > > Wayne: potatoes on a car? > > Hana .: yer lol its fun and they taste nicer lol, you wrap a potato in > tinfoil a > nd put in on the engine of a car and close the bonnet and have the engine > run an > d it cooks it in about 30 mins > > Speed isn't as important as ease of use, I suppose, since > > non-technical people should be able to use it, ideally. I guess the easiest for your team would be to: * let the script write the result lines into a text file * let the script open the result in an editor (using module called subprocess) * put a link to your script on the desk ### just an example # write to file target = open("target.txt",'w') for line in lines: target.write(line) target.close() # open in editor import subprocess subprocess.call(["gedit","target.txt"]) print "*** end ***" denis -- la vida e estranya ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Finding the End of a Def?
"Wayne Watson" wrote I'm using pythonWin. Is there some way to skip from the start of a def to the end? That doesn't seem to be supported. The documentation is found in the help structure under PyWin32 Documentation -Pythonwin and win32ui -Overviews -Keyboard Bindings If using Pythonwin keyboard commands you should look at the docs for the underlying editing widget Scintilla: http://www.scintilla.org/SciTEDoc.html That reveals quite a number of extra navigation commands. The nearest to what you want is next paragraph (Ctr-] ) Pythonwin does modify a few of the standard commands so you need to look in the Pythonwin help first then at Scintilla. But I'm surprised there are no block movement commands given Scintilla's primary goal of supporting programmers You can of couse use the folding feature to speed navigation between functions etc... Keypad * will fold/unfold everything... HTH, -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Finding the End of a Def?
Title: Signature.html If you are familiar with vi and C, one could enter a simple keystroke and jump from an opening paren to the corresponding closing one. I've long forgotten most of C, but here's a rough segment of a program: main() ( while (x ==True) ( a =5; ) ... ) If your cursor was on the second "(", pressing a key would take you to the third one. I want something like it for def. Where's the end of the def. Some def blocks are so long it's almost impossible to find where they end. spir wrote: Le Fri, 23 Jan 2009 22:25:05 -0800, Wayne Watson a écrit : I'm using pythonWin. Is there some way to skip from the start of a def to the end? How about any similar indentation? Sorry, I don't understand what you wish... Do you mean while parsing a source code file? Denis -- la vida e estranya -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) Copper and its alloys have been found effective in hospital sinks, hand rails, beds, ... in significantly reducing bacteria. Estimates are 1/20 people admitted to a hospital become infected, and 1/20 die from the infection. -- NPR Science Friday, 01/16/2009 Web Page:___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Finding the End of a Def?
On Sat, Jan 24, 2009 at 7:06 AM, Wayne Watson wrote: > If you are familiar with vi and C, one could enter a simple keystroke and > jump from an opening paren to the corresponding closing one. > > I've long forgotten most of C, but here's a rough segment of a program: > > main() > ( > while (x ==True) > ( >a =5; > > ) > ... > ) > If your cursor was on the second "(", pressing a key would take you to the > third one. I want something like it for def. Where's the end of the def. > Some def blocks are so long it's almost impossible to find where they end. > > Presuming, of course, that your def statement is followed by another, finding the "next" def would get you there. Other than that... you may just have to figure out how to write your own bindings. HTH, Wayne ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Finding the End of a Def?
Title: Signature.html I'm really just starting with pythonwin editor, after having used IDLE. Comments interspersed. Alan Gauld wrote: "Wayne Watson" wrote I'm using pythonWin. Is there some way to skip from the start of a def to the end? That doesn't seem to be supported. "in the help structure"? This, in Tutorial section of Help documentation? = start image = end image I did find key bindings in Help, but see nothing about skipping to the end of a block. It seems like this should be a feature. I'm looking at someone else's code, and some def blocks go well over a page. I just keep looking for the margin seems to fold back. See my comments about vi in my recent post above this one. The documentation is found in the help structure under PyWin32 Documentation -Pythonwin and win32ui -Overviews -Keyboard Bindings If using Pythonwin keyboard commands you should look at the docs for the underlying editing widget Scintilla: This is unfamiliar territory. http://www.scintilla.org/SciTEDoc.html That reveals quite a number of extra navigation commands. The nearest to what you want is next paragraph (Ctr-] ) Pythonwin does modify a few of the standard commands so you need to look in the Pythonwin help first then at Scintilla. But I'm surprised there are no block movement commands given Scintilla's primary goal of supporting programmers You can of couse use the folding feature to speed navigation between functions etc... Keypad * will fold/unfold everything... Interesting, but it folds way too much. HTH, -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) Copper and its alloys have been found effective in hospital sinks, hand rails, beds, ... in significantly reducing bacteria. Estimates are 1/20 people admitted to a hospital become infected, and 1/20 die from the infection. -- NPR Science Friday, 01/16/2009 Web Page:___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Defining "bit" type
Hello. As fas as I know, there is a "bytes" type in Python 3, which is a sequence of bytes. Anyway, I am working with Python 2.5.4, and I am interested in defining a new type called "bit" (if possible), which represents a number that can only take values 0 or 1 —that's what we would call a "binary variable", in a Mathematical Programming context. I want to define that new data type within my code, so that I can use it in the same way I would use "int", "long" and "float" data types, for instance. How can I do that? If you can give me some hint or any web reference, I would appreciate it. Thank you in advance. -- Vicent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Finding the End of a Def?
I'm not at all tempted (binding). VBG. Page scroll and a steady eye on the left margin works well for my current purposes. However, I am surprised such a feature doesn't exist. W W wrote: On Sat, Jan 24, 2009 at 7:06 AM, Wayne Watsonwrote: If you are familiar with vi and C, one could enter a simple keystroke and jump from an opening paren to the corresponding closing one. I've long forgotten most of C, but here's a rough segment of a program: main() ( while (x ==True) ( a =5; ) ... ) If your cursor was on the second "(", pressing a key would take you to the third one. I want something like it for def. Where's the end of the def. Some def blocks are so long it's almost impossible to find where they end. Presuming, of course, that your def statement is followed by another, finding the "next" def would get you there. Other than that... you may just have to figure out how to write your own bindings. HTH, Wayne -- Signature.html Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) Copper and its alloys have been found effective in hospital sinks, hand rails, beds, ... in significantly reducing bacteria. Estimates are 1/20 people admitted to a hospital become infected, and 1/20 die from the infection. -- NPR Science Friday, 01/16/2009 Web Page: ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Fwd: Defining "bit" type
Sorry, I answered only to Eugene... -- Forwarded message -- From: Vicent Date: Sat, Jan 24, 2009 at 15:42 Subject: Re: [Tutor] Defining "bit" type To: Eugene Perederey On Sat, Jan 24, 2009 at 15:31, Eugene Perederey wrote: > Hi, > type 'bool' takes only True and False. Is it what you want? > > Well, it would be similar, but... This is OK: >>> a = True >>> type(a) >>> a == 1 True >>> not a False >>> (not a) == 0 True >>> a*0.5 0.5 >>> a*a 1 >>> type(a) But this is not nice: >>> type(a) >>> a True >>> a = 0 >>> type(a) I mean, being "a" a boolean variable, it works as if it was a number, but every time I want to update the value of "a", I must put "False" for 0 and "True" for 1, or it will change into an integer variable. So, maybe I can adapt the definition of "bool" type, I don't know... Anyway, I want to manage 0's and 1's, not "Falses" and "Trues". -- Vicent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Defining "bit" type
On Sat, Jan 24, 2009 at 15:42, Vicent wrote: > > > > I mean, being "a" a boolean variable, it works as if it was a number, but > every time I want to update the value of "a", I must put "False" for 0 and > "True" for 1, or it will change into an integer variable. > > So, maybe I can adapt the definition of "bool" type, I don't know... > Anyway, I want to manage 0's and 1's, not "Falses" and "Trues". > I don't know if it is possible to define a "bit" class based on the "bool" type. I mean, I don't know how to do those kind of things... -- Vicent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Defining "bit" type
On Sat, Jan 24, 2009 at 9:38 AM, Vicent wrote: > >> So, maybe I can adapt the definition of "bool" type, I don't know... >> Anyway, I want to manage 0's and 1's, not "Falses" and "Trues". >> > Well, I can think of something that might be of some help: In [18]: bit = {True:1, False:0} In [19]: bit[True] Out[19]: 1 In [20]: bit[False] Out[20]: 0 In [21]: bit Out[21]: {False: 0, True: 1} In [22]: x = False In [23]: bit[x] Out[23]: 0 That might give you something to work with. Anyway, HTH, Wayne ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Defining "bit" type
If your actual interest in defining a bit type is to work with an array of bits, try Ilan Schnell's bitarray module (http://pypi.python.org/pypi/bitarray/0.3.4). It uses a compiled extension, so it is quite fast and space-efficient. Ilan gave a presentation on this at the Texas Unconference last fall, and some of the applications were pretty interesting/novel. If you download the tarball from PyPI, there is an included examples directory. -- Paul ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Defining "bit" type
On Sat, Jan 24, 2009 at 17:31, Paul McGuire wrote: > If your actual interest in defining a bit type is to work with an array of > bits, try Ilan Schnell's bitarray module > (http://pypi.python.org/pypi/bitarray/0.3.4). It uses a compiled > extension, > so it is quite fast and space-efficient. > > Ilan gave a presentation on this at the Texas Unconference last fall, and > some of the applications were pretty interesting/novel. If you download > the > tarball from PyPI, there is an included examples directory. > Well, not necessarily —but I'll give it a look. Thanks. -- Vicent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Finding the End of a Def?
"Wayne Watson" wrote You can of couse use the folding feature to speed navigation between functions etc... Keypad * will fold/unfold everything... Interesting, but it folds way too much. yes but you can use other keys to fold just the current function, or even a while loop within a function or an if statement etc. Its a very powerful feature and one of the reasons I use SciTe as an alternative editor to vim (vim supports folding too but its much more clunky IMHO). Using folding you can always collapse a function to fit on a single screen and focus on just the 10-20 lines that really interrest you.. But for rapid movement around files Fold All, a mouse click and then un-Fold All is very effective. But I do agree that block level navigation seems a glaring gap in Scintilla's features as a programmers editor -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Defining "bit" type
"Vicent" wrote Anyway, I am working with Python 2.5.4, and I am interested in defining a new type called "bit" (if possible), which represents a number that can only take values 0 or 1 —that's what we would call a "binary variable", in a Mathematical Programming context. If its a single binary digit you want then it would be relatively easy to define a class. The operations you need would largely be the comparison and arithmetic ones. But while its not difficult it is tedious and you would need to think about the Exceptions you need to raise for carry errors etc. For example what would be the result of adding two Bits both valued 1. Would the result be a new zero Bit or an Overflow exception? Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Defining "bit" type
On Sat, Jan 24, 2009 at 18:19, Alan Gauld wrote: > > If its a single binary digit you want then it would be relatively easy to > define a class. The operations you need would largely be the > comparison and arithmetic ones. But while its not difficult it is > tedious and you would need to think about the Exceptions you > need to raise for carry errors etc. For example what would be the > result of adding two Bits both valued 1. Would the result be a > new zero Bit or an Overflow exception? > > Alan G. > That's a good question... Now, when you add up two booleans valued "True", you get 2: >>> a = True >>> b = True >>> a+b 2 So, maybe I can just build a class that is like a "translator" of True/False into 1/0, but that also admits 1/0 in assignation statements. For my purposes, maybe it is not necessary to handle with many unexpected behaviors... As I am a beginner, I still don't know how to build that class, but I guess Wayne gave me the clue, or something to play with. -- Vicent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Defining "bit" type
Vicent wrote: Hello. As fas as I know, there is a "bytes" type in Python 3, which is a sequence of bytes. Anyway, I am working with Python 2.5.4, and I am interested in defining a new type called "bit" (if possible), which represents a number that can only take values 0 or 1 —that's what we would call a "binary variable", in a Mathematical Programming context. I want to define that new data type within my code, so that I can use it in the same way I would use "int", "long" and "float" data types, for instance. The problem is: there is no way that I know of to add fundamental types to Python. Also realize that variables are dynamically typed - so any assignment can create a variable of a new type. That is why a = 0 results in an int. So one must resort, as others have mentioned, to classes. Framework (untested): class Bit: _value = 0 # default def __init__(self, value): self._value = int(bool(value)) def getvalue(self): return self._x def setvalue(self, value): self._x = int(bool(value)) value = property(getvalue, setvalue) def __add__(self, other): # causes + to act as or self._value |= other def __mul__(self, other): # causes * to act as and self._value &= other b = Bit(1) b.value # returns 1 b.value = 0 b.value # returns 0 b.value + 1 # sets value to 1 b.value * 0 # sets value to 0 -- Bob Gailer Chapel Hill NC 919-636-4239 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Defining "bit" type
On Sat, Jan 24, 2009 at 19:48, bob gailer wrote: > The problem is: there is no way that I know of to add fundamental types to > Python. Also realize that variables are dynamically typed - so any > assignment can create a variable of a new type. That is why a = 0 results in > an int. > > So one must resort, as others have mentioned, to classes. > Yes, that's what I understood from previous answers. > Framework (untested): > > class Bit: > _value = 0 # default > def __init__(self, value): > self._value = int(bool(value)) > def getvalue(self): > return self._x > def setvalue(self, value): > self._x = int(bool(value)) > value = property(getvalue, setvalue) > def __add__(self, other): # causes + to act as or > self._value |= other > def __mul__(self, other): # causes * to act as and > self._value &= other > > b = Bit(1) > b.value # returns 1 > b.value = 0 > b.value # returns 0 > b.value + 1 # sets value to 1 > b.value * 0 # sets value to 0 > > Wow! that's great. I'll give it a try. It would be great if "b.value = 0" could be just written as "b = 0" without changing type as a result. What happens if every time I want to update the value of "b", I use "b= Bit(0)" , "b=Bit(1)", and so on?? Is like "building" the object each time? It is less efficient, isn't it? You are going to kill me, but... Maybe the solution is not to re-define what already exists —boolean data type, but just using it, as suggested at the beginning of the thread... b = bool(1) b = bool(0) After all, it's not so bad... I'll think about it. -- Vicent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Defining "bit" type
Vicent wrote: On Sat, Jan 24, 2009 at 19:48, bob gailerwrote: The problem is: there is no way that I know of to add fundamental types to Python. Also realize that variables are dynamically typed - so any assignment can create a variable of a new type. That is why a = 0 results in an int. So one must resort, as others have mentioned, to classes. Yes, that's what I understood from previous answers. Framework (untested): class Bit: _value = 0 # default def __init__(self, value): self._value = int(bool(value)) def getvalue(self): return self._x def setvalue(self, value): self._x = int(bool(value)) value = property(getvalue, setvalue) def __add__(self, other): # causes + to act as or self._value |= other def __mul__(self, other): # causes * to act as and self._value &= other b = Bit(1) b.value # returns 1 b.value = 0 b.value # returns 0 b.value + 1 # sets value to 1 b.value * 0 # sets value to 0 Wow! that's great. I'll give it a try. It would be great if "b.value = 0" could be just written as "b = 0" without changing type as a result. Assignment in effect does a del b, then creates a new b based on the _expression_. There is no way in Python right now to do that. The closest I can come is to support the syntax b(0) and b(1) to emulate assignment. That would require that I add to the Bit class: def __call__(self, value): self.value = value What happens if every time I want to update the value of "b", I use "b= Bit(0)" , "b=Bit(1)", and so on?? Is like "building" the object each time? It is less efficient, isn't it? Yes and yes. You are going to kill me Are you saying that to prepare your self for a negative response from me, or in hopes that I would not have such? I view everything we do here as incremental improvement. I am glad you are thinking of alternatives. , but... Maybe the solution is not to re-define what already exists —boolean data type, but just using it, as suggested at the beginning of the thread... b = bool(1) b = bool(0) After all, it's not so bad... It really depends on your goals for having this new type. -- Bob Gailer Chapel Hill NC 919-636-4239 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] [Web] Using pyCrypto - pyscard
Hello, I have a question concerning the use of python to make web application. I don't know if it is possible. I would like to create an applet capable of using the client smardcard (with pyscard/pyCrypto module) reader to read and display the contained data on the page. I already have a simple python application that does it. My question is the following: Is it possible to port it into an applet? Thank in advance, Olivier ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Fwd: Defining "bit" type
On Sat, Jan 24, 2009 at 10:36 AM, Vicent wrote: > But this is not nice: > type(a) > a > True a = 0 type(a) > > > > I mean, being "a" a boolean variable, it works as if it was a number, but > every time I want to update the value of "a", I must put "False" for 0 and > "True" for 1, or it will change into an integer variable. > > So, maybe I can adapt the definition of "bool" type, I don't know... Anyway, > I want to manage 0's and 1's, not "Falses" and "Trues". You have an incorrect idea about how variables and assignment work in Python. Type is associated with a value, not a name. You might want to read this: http://personalpages.tds.net/~kent37/kk/00012.html and this classic: http://effbot.org/zone/python-objects.htm Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] [Web] Using pyCrypto - pyscard
On Sat, Jan 24, 2009 at 10:10 AM, Olivier Roger wrote: > Hello, > > I have a question concerning the use of python to make web application. > I don't know if it is possible. I would like to create an applet capable of > using the client smardcard (with pyscard/pyCrypto module) reader to read and > display the contained data on the page. > > I already have a simple python application that does it. My question is the > following: Is it possible to port it into an applet Presuming that by 'applet' you mean something that runs client-side in a web browser, your options for doing this with Python are very limited. - You can use IronPython within MS Silverlight - There may be ways to do this with Firefox and IE but they are obscure Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Finding the End of a Def?
On Sat, 24 Jan 2009 11:43:00 +, Alan Gauld wrote: > > But I'm surprised there are no block movement commands given Scintilla's > primary goal of supporting programmers > I guess because block level movement is ambiguous in any programming language supporting nested class/function definition? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Finding the End of a Def?
Title: Signature.html Not in C. Lie Ryan wrote: On Sat, 24 Jan 2009 11:43:00 +, Alan Gauld wrote: But I'm surprised there are no block movement commands given Scintilla's primary goal of supporting programmers I guess because block level movement is ambiguous in any programming language supporting nested class/function definition? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) Copper and its alloys have been found effective in hospital sinks, hand rails, beds, ... in significantly reducing bacteria. Estimates are 1/20 people admitted to a hospital become infected, and 1/20 die from the infection. -- NPR Science Friday, 01/16/2009 Web Page:___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] [Web] Using pyCrypto - pyscard
"Olivier Roger" wrote I have a question concerning the use of python to make web application. I don't know if it is possible. I would like to create an applet capable of using the client smardcard (with pyscard/pyCrypto module) reader to read and display the contained data on the page. I already have a simple python application that does it. My question is the following: Is it possible to port it into an applet? Let me check my understanding... This existing application runs on the same computer as the card reader, right? Presumably it is doing some kind of low level OS calls to read the hardware? If that's the case you probably couldn't use an applet even if you could write it since the applet wouldn't normally be able to access the local PCs hardware - way too much security risk! If on the other hand the card reader is on a server then you don't need an applet you need a web app on the server that calls your existing application then displays the result as a web page. Does that help? -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Finding the End of a Def?
"Lie Ryan" wrote But I'm surprised there are no block movement commands given Scintilla's primary goal of supporting programmers I guess because block level movement is ambiguous in any programming language supporting nested class/function definition? Most programmers editors I've used in the past have had some kind of block commands.vim and emacs both use the end-of-paragraph text mode commands as end of block commands when in code modes. Thats why, as I said earlier, the next-paragraph seems to be the best scintilla can do. Alan G ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Finding the End of a Def?
Title: Signature.html Ah, well. Back to the Scroll key. :-) Alan Gauld wrote: "Lie Ryan" wrote But I'm surprised there are no block movement commands given Scintilla's primary goal of supporting programmers I guess because block level movement is ambiguous in any programming language supporting nested class/function definition? Most programmers editors I've used in the past have had some kind of block commands.vim and emacs both use the end-of-paragraph text mode commands as end of block commands when in code modes. Thats why, as I said earlier, the next-paragraph seems to be the best scintilla can do. Alan G ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) Copper and its alloys have been found effective in hospital sinks, hand rails, beds, ... in significantly reducing bacteria. Estimates are 1/20 people admitted to a hospital become infected, and 1/20 die from the infection. -- NPR Science Friday, 01/16/2009 Web Page:___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Possible to search text file for multiple string values at once?
Excellent ideas...thanks to you all for the input. I will see what I can work out in the next few days and report back. :) Scott On Sat, Jan 24, 2009 at 2:16 AM, spir wrote: > Le Fri, 23 Jan 2009 14:45:32 -0600, > W W a écrit : > >> On Fri, Jan 23, 2009 at 1:11 PM, Scott Stueben wrote: >> >> > Thanks for the help so far - it seems easy enough. To clarify on the >> > points you have asked me about: >> > >> > A sqlite3 database on my machine would be an excellent idea for >> > personal use. I would like to be able to get a functional script for >> > others on my team to use, so maybe a script or compiled program >> > (Win32) eventually. >> >> >> As long as everyone on your team has python installed (or as long as python >> is installed on the machines they'll be using), a functional script would be >> fairly easy to get rolling. Sqlite is (AFAIK) included with the newer >> versions of python by default. Heck, it's on the version I have installed on >> my phone! (Cingular 8525). Simply zipping up the directory should provide an >> easy enough distribution method. Although, you *could* even write a python >> script that does the "install" for them. >> >> >> > As for output, I would probably like to return the entire lines that >> > contain any search results of those strings. Maybe just output to a >> > results.txt that would have the entire line of each line that contains >> > 'Bob', 'John', 'Joe', 'Jim', and or 'Fred'. >> >> >> The simplest method: >> >> In [5]: f = open('interculturalinterview2.txt', 'r') >> >> In [6]: searchstrings = ('holy', 'hand', 'grenade', 'potato') >> >> In [7]: for line in f.readlines(): >>...: for word in searchstrings: >>...: if word in line: >>...: print line >>...: >>...: >> Hana: have a bonfire n candy apples n make potatoes on a car lol! >> >> Wayne: potatoes on a car? >> >> Hana .: yer lol its fun and they taste nicer lol, you wrap a potato in >> tinfoil a >> nd put in on the engine of a car and close the bonnet and have the engine >> run an >> d it cooks it in about 30 mins >> >> Speed isn't as important as ease of use, I suppose, since >> > non-technical people should be able to use it, ideally. > > I guess the easiest for your team would be to: > * let the script write the result lines into a text file > * let the script open the result in an editor (using module called subprocess) > * put a link to your script on the desk > > ### just an example > # write to file > target = open("target.txt",'w') > for line in lines: >target.write(line) > target.close() > > # open in editor > import subprocess > subprocess.call(["gedit","target.txt"]) > print "*** end ***" > > denis > > -- > la vida e estranya > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > -- "Shine on me baby, cause it's rainin' in my heart" --Elliott Smith ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Traversing XML Tree with ElementTree
I want to traverse an xml file and at each node retain the full path from the parent to that node ie. if we have: this is node b this is node c this is node d this is node e ... then require: this is node b this is node c this is node d this is node e I found this code on the Comp.Lang.Python list but it doesn't retain the full path. import xml.etree.ElementTree as ET tree = ET.parse(xmlfile) def traverse(node): for c in node.getchildren(): print c.tag, ':', c.text traverse(c) root = tree.getroot() traverse(root) Any ideas how to do this? Thanks Dinesh ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Fw: Traversing XML Tree with ElementTree
i've got most of this working now so hold off (for now). thanks. dinesh From: Dinesh B Vadhia Sent: Saturday, January 24, 2009 8:31 PM To: tutor@python.org Subject: Traversing XML Tree with ElementTree I want to traverse an xml file and at each node retain the full path from the parent to that node ie. if we have: this is node b this is node c this is node d this is node e ... then require: this is node b this is node c this is node d this is node e I found this code on the Comp.Lang.Python list but it doesn't retain the full path. import xml.etree.ElementTree as ET tree = ET.parse(xmlfile) def traverse(node): for c in node.getchildren(): print c.tag, ':', c.text traverse(c) root = tree.getroot() traverse(root) Any ideas how to do this? Thanks Dinesh ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor