makeSentence is a function of the class App. It should be called as such App.makeSentence
PoovenM commented: AWw man you're brilliant :D +2
jlm699 320 Veteran Poster
makeSentence is a function of the class App. It should be called as such App.makeSentence
Your current problem is probably that the location of easy_install is not on your windows path. For now, try typing in the full path to where you installed easy_install as such: C:\\Program Files\\<etc, etc>\\easy_install speech
.
Here's one making use of list comprehension:
>>> def FirstLetters( s ):
... return ''.join( [ lett[0] for lett in s.split() ] )
...
>>> FirstLetters( 'My mother used to bake apple pies in the foo bar' )
'Mmutbapitfb'
>>>
"abcd_asdf" and the string in which I am searching is " aaslkdfn_abcd_asdf_asgd"
I also want to search for "abcd" and "asdf" and "_" individually.
Here's another example:
>>> test1 = 'aaslkdfn_abcd_asdf_asgd'
>>> ret = re.search('.*_(abcd)(_)(asdf)_.*', test1)
>>> ret.group(0)
'aaslkdfn_abcd_asdf_asgd'
>>> ret.group(1)
'abcd'
>>> ret.group(2)
'_'
>>> ret.group(3)
'asdf'
>>> ret.groups()
('abcd', '_', 'asdf')
>>>
You can identify substrings using the () characters within your pattern; for example:
>>> import re, os, sys
>>> tests = [ 'NM4_ACT', 'NM4_SAND', 'NM3_BOO', 'NM5_FOOBAR', 'NM4_DUMP', 'NM4_SUNSET', 'NM4_SOUTH_VALLEY' ]
>>> for each in tests:
... ret = re.search('^NM4_(.*)$', each)
... if ret:
... ret.groups()
...
('ACT',)
('SAND',)
('DUMP',)
('SUNSET',)
('SOUTH_VALLEY',)
>>>
As you can see, by using the groups() or group() functions you can extract the substrings that were identified in your pattern after a match is found. HTH
c = t.open_session()
if timeOut != None:
c.settimeout(timeOut)
This is an excerpt from a function that sends a command to the Server. Keep in mind that I'm using paramiko here, so it probably won't work for you unless you too are using paramiko.
The usage depends on what interface you're using to make your client/server (I've only ever used paramiko); however you could probably make use of a global timeout setting. This way after a set amount of time the recv() operation will throw a timeout exception, which you can catch and handle however you would like.
Hello. The problem with your solution is that it works only on windows.
While that may be true you have to consider this: If you're using excel it's almost a guarantee that it's in a windows environment anyway.
I don't know why anybody on a Mac or *nix box (in their right mind) would use Excel...
I am the same way. Before coming to this forum I used to prowl another forum, which has degraded into abysmal territories and I will never again return to; however, I used to ask a question, and simply by typing out my queries I would in fact brainstorm with myself and solve the problem before a single member was able to reply.
So I'm right there with you ;)
What are you using to connect to your server? I've worked with paramiko and know that it provides a universal timeout, which will throw a TimeoutException when any transaction with the server/client goes beyond the desired limit... Perhaps something along those lines would get you what you need.
I don't know; as I've never used it. If that does not suit your needs you'll possibly need to look into the Excel API; which can be access via win32com (you'll need to learn how to use COM objects).
Would it be possible for you to simply use a read() to bring in all the information that you can and then worry about parsing it once that operation has completed?
After storing what you've read you can perform a split('\n') and then iterate on the return to perform almost exactly like readline().
Alternately you could perform readlines(), which is basically exactly like doing a read and then splitting it up by line (returns a list).
Since there is no A2 in your code; and judging by the content of the error message; I would assume that you have imported the maya.cmds module incorrectly. I would look into the documentation for an example of how to properly use said module.
Not exactly sure what it is you're looking for. But many built-in objects can have the str() function applied to them with little problem.
If it's a custom class or similar you may need to look into the Pickling module. I don't know if you plan to use the string for something other than storing it on your FS; however here's the documentation.
Sorted should be built-in to your Python dist. What version are you using? Try opening an interpreter and typing in sorted([1,3,2,5,4,7,6])
to see if you get the same error or if it returns the sorted list.
Here's how you could iterate through a file:
fh = open( 'myFile.txt', 'r' )
inp = fh.readlines()
fh.close()
for each_line in inp:
# Do something here
All you'll need to do is make a counter and increment it when you find what you're looking for.
P.S. when you use code tags it helps if you define the language via so that syntax highlighting is turned on. This makes it loads easier to read.
[code=python] for this forum (usually)[code=xxxx] so that syntax highlighting is turned on. This makes it loads easier to read.
for this forum (usually)[code=python] for this forum (usually)
After you open the file for reading you can iterate over each line like so:
fh = open('myfile.txt', 'r')
lines = fh.readlines()
fh.close()
for each_line in lines:
## split each line now like woooee pointed out above and do your processing...
You can interact with Python and execute code as you see fit. My favorite thing about Python is being able to simply type in examples to the Interpreter and see how my programs will react to different test cases.
Hi,
1. I'm inserting an empty list because I need to insert the values into that column, as opposed to appending it. I am checking if the element encountered is Date, in which case I insert an emptylist. In the next iteration, I say rec[1] = avgvolume, effectively inserting the values into column 1.
2. I did that because my counter was not working.. I figured if I looped over inplis again then maybe my counter would take the values of i? Apparently not, so that was wrong.
3. I used map so that I could convert the entire list into a string, so as to write it into a new file, since it needs to be in string form in order to write into outp.
1. You don't need to insert an empty list and then replace it, you could simply do it one step by rec.insert(1, avgVolume)
...
2. In your loop 'i' is not a number. It is each line (which is why you did i.strip().split() remember? ). You should simply be using counter += 1
, which is equivalent to counter = counter + 1
. That way you're incrementing by one every time.
3. I completely took the wrong meaning of that last part... I was thinking in terms of C++ maps and forgot about Python's map function! Sorry ;)
Instead of while counter == 20
you should simply check if counter == 20
.
Additionally, you should remove the import …
There are a number of things that I don't understand what you are trying to do in this code. First and foremost:
if rec[0] == 'Date':
rec.insert(1,emptyList)
continue
Why are you inserting an empty list into your data and then forcing execution to the next iteration (effectively nullifying inserting the empty list) ??
Second, why are you iterating over the same object within the first for loop? That also makes no sense to do.
Third, you don't need to import string to use join. Simply use ','.join( map( str, rec ) )
, which brings me to my next point.
What are you trying to do there? map(str,rec)? You have no object named str, and if you did it would be a bad idea since str() is a reserved method for converting objects into strings.
Yes, it is defined within the same class but not in the scope of the function OnRecognition. say() is a member of the ContextEvents class so you'll need to call it as self.say()
Hmm, it's hard to say exactly what's wrong without having an example of the contents of table.csv; however upon initial inspection I see a glaring problem. Since you're not incrementing counter by 1 (rather a variable length), I would imagine you're missing the opportunity to enter the while counter == 20:
loop.
Perhaps you could provide with an example of what's in that file so we can take a more complete look at the problem here.
I don't know about getopt but all of those things are stored in the list stored under sys.argv
>>> import sys
>>> sys.argv[0]
>>> len(sys.argv)
Try those lines and then you should be able to handle the command line arguments yourself.
That is because like I said: if the regex doesn't match anything it returns a None. Try checking your code line by line in an interpreter to see what's happening I got to the line that says r = curl(o+'RedirLogin.aspx?auth=%s' % auth, get_header=True)
. When you check the value of 'r' you see that there is no orkut_state= anything.
$r = curl($o."RedirLogin.aspx?auth=$auth",1,0,1,null);
Right here. In your python script you have 'auth=auth'.
It should be r = curl(o+"RedirLogin.aspx?auth=%s" % auth, get_header = True)
I don't know how that is not giving you any errors. There is no indentation and you're missing the %s %s
after the cp command on the last line.
You're getting an Indentation error. I didn't type that out in an editor so the indentation will be off. Go through and re-tab all the lines that should be tabbed.
An example usage: python copy.py my_favorite_image.jpg
If your regex doesn't match anything it returns a None, which gets stored to m. You should have a check before accessing m.groups by saying if m:
import sys, os
if len(sys.argv) != 2:
print 'Usage: python copy.py <file_to_copy>'
sys.exit(0)
if sys.platform[:3] == 'win':
os.system('copy %s %s' % (sys.argv[1], 'copy' + sys.argv[1]))
elif sys.platform[:5] == 'linux':
os.system('cp %s %s' % (sys.argv[1], 'copy' + sys.argv[1]))
Hi guys, thank you so much. Jlm699 was correct, I needed to commit the changes to the database. I knew that there was a commit call that has to be used but I was calling it on the cursor (cur) :icon_redface:
And I agree, I haven't really seen tables being used the way I have (that is: fdi.fdiresults) but it does work. The fdi is the schema and fdiresults is the table. Clever use of SQL there mate :icon_cool:Once again, thanks guys!
It's understandable that you'd try to commit the cursor instead of 'conn', mainly because you've tricked yourself by using that nomenclature! The return of psycopg2.connect() is actually a database object! Maybe it'd help your thinking if you changed all instances of conn to db or my_db? That's what I did!
I'm glad we could help.
This doesn't belong in this forum... however I imagine when you say you "started the CD up" you mean that you're still in Windows and you just popped it into your disc drive. You need to understand that when it comes to an operating system, it's not just another program that you're installing.
What you need to do is boot to the CD. It is hard to say exactly what you need to do without knowing your system but there is a chance that you could simply reboot your computer with the CD in the drive, and it will automatically boot into the CD. If not you'll need to open up your BIOS settings (immedately after your computer turns on you press F1 or F2... there's usually a prompt that says press F# to enter Setup...), and then look around for start-up options or boot order or something similar. In there you'll want to switch the order of bootable devices around so that your CD-ROM drive is before your Hard Drive.
Keep in mind however that when installing an OS, you have the possibility of wiping your hard drive clean of all data! Some Linux distros will set you up with a dual boot and allow you to have both Linux and Windows on your computer. Also many distros will let you simply run Linux from the CD without installing to your hard drive so that you could try it out before you commit.
Sorry for the …
(Note that semicolons are not used in Python.)
When I was writing a data collecting application that interfaced with pgSQL via psycopg2 I tried out both ways (a query with and without a semicolon), neither of which threw any errors.
And that line ...SELECT etc, is what he typed into his Postgres GUI, not python.
In my experience with regex you can combine two different regexes with an '|' (or operator). So within the quotes just place a '|' between each regex (without single quotes)'
Like so:
tennis_players = re.compile("<div class=\"entrylisttext\">([\d+]*)</div>|playernumber=[A-Z][0-9]+\" id=\"blacklink\">([a-zA-Z]+, [a-zA-Z]+)|pointsbreakdown.asp\?player=[A-Z][0-9]+&ss=y\" id=\"blacklink\">([0-9]+)|playeractivity.asp\?player=[A-Z][0-9]+\" id=\"blacklink\">([0-9]+)", re.I | re.S | re.M)
When using psycopg2 your operations are only transactions. In order to get your transaction to commit to the database you'll need to issue a conn.commit()
command.
Here's a few things to get you on your way:
>>> inp = 'clear|foobar'
>>> inp.find('clear|')
0
>>> inp.rfind('|')
5
>>> inp[5+1 : ] # This is slicing
'foobar'
>>> inp.split('|')
['clear', 'foobar']
>>> inp.split('|')[1]
'foobar'
>>>
import random
def getRandomFiveLetterWord(e):
file = open(e, "r")
That format of opening a file is not wrong its the fact that you're using 'file' as your variable name. Just change the name to something like fh (file handler) or similar. That is completely arbitrary.
t = file.read()
for line in file:
randomWord = random.choice(t[0], t[-1])
Here you are reading the entire file into 't', yet in your for loop you're iterating over the file object, which makes no sense, and is also the cause of your problem. Since you are reading the entire contents of the file, the file pointer traverses all the way through the file until it hits the EOF (end of file marker), which is where it sits until told otherwise.
When you try to perform for line in file
the pointer is already at EOF so the for loop never runs, which is why randomWord is never declared and why you are receiving your error.
Furthermore, you still missed my point about what you pass to random.choice(). It's supposed to be a list. Whereas you are passing it the first and last character of the file contents. Why don't you try feeding some of this code into your interpreter (and here you will learn the strength of Python, being able to interact with your code to find problems); for your sake just try the following lines:
fh = open('fiveLetterWords.txt', "r") # Open the file for reading
t = fh.read() # Read …
I simply created a Help menu option and bound this function to it.
My chm file and all related pages were zipped up, which is why I need the ZipFS Handler, but you can do without.
def OnHelp(self, event=None):
import wx.html
wx.FileSystem_AddHandler(wx.ZipFSHandler())
self.help = wx.html.HtmlHelpController( style = wx.html.HF_TOOLBAR |\
wx.html.HF_CONTENTS | wx.html.HF_SEARCH | wx.html.HF_PRINT)
self.help.AddBook(os.path.join(Global.progfiles_path, 'STHelp.zip')):
self.help.Display('Index.htm')
You can set up a timer no problem and use that as your event-driving mechanism. Say a repeating five minute timer, which goes off and runs your autobackup script, dumping the results to the TextCtrl
There are a number of problems here. First of all, that text file contains five letter words that are all appended together without any whitespace whatsoever.
Secondly, do not use file as one of your variable names. As you can see above, file is highlighted in purple meaning that it is a reserved word in Python.
Third, as the error is telling you, you cannot use subscript notation on a file object (file). You read the contents of the file into the variable t. At the very least you should be trying to use subscripts on t (even though that would still be wrong).
randint returns a random integer, not a word. What you want is random.choice, which you would pass a *LIST* of words to. Not a gigantic single word that you're expecting the program to magically understand to be a listing of five letter words.
So first either break up your text file into words or write a small function to read in the file contents and return a list of words.
Then implement the proper random function.
[] designates a group of characters to match.. you had [d+] in there, meaning that you wanted to match any of the digits 0-9 as well as the plus symbol. An equivalent statement would be [0-9+], or typing the entire set of digits out would be [0123456789+]. By placing an * after your group of matchable characters that means match this as many times as possible. So the * solves the "only matches single digit" problem. The () are what gave the ability to extract a specific part of the text out of the matched text. Anything that is enclosed in parenthesis is able to be extracted after the pattern is matched.
P.S. if you meant to use '+' as match 1 or more times then it would have to be outside of the square brackets. Read up on regular expression syntax for more info.
HTH
I think that it would be better if you learned PHP instead. PHP is free, open source web programming language. It can also be used for other scripting things.
I completely disagree. Being that PHP is a "web programming" language, it is nowhere near as easy and accessible for a learning programmer as Python. Python is also free and open-source. Being able to open a Python shell and interact with the interpreter is the best part because you can test a single line of code without generating a test case and encapsulating it in an entire program that would then need to be uploaded to your web server and then viewed via web browser.
Long story short Python is much easier to learn than PHP and will not have as sharp a learning curve.
A very crude method would be to capture your output, and then execute the same command via os.system or a similar call.
Alternately you could make use of smtplib to send the email to a mail server's listener, and send it that way.
Example of using smtplib.
Keep in mind that in this example, the mail listening agent is on the same machine as the script is running. If this is not the case you'll need the ip address and port that the mail daemon is listening on of the server where this service is running.
wxPython, like most other GUI modules is event driven. This means that until something triggers an event, processing is more or less waiting for something to happen.
I'm not sure what you mean by appending text afterwards? Do you mean literally after the mainloop() statement? Because the program stays in the mainloop() until the application is closed.
What you'll need to do is create an event that will allow you to input text and then use your appendText method to append it to the textCtrl.
I would suggest binding an event within Frame1's __init__ method that captures a key press, pops up a TextInputDialog, and then captures the input from the Text dialog and appends it to the textCtrl
What do you mean freeze them but still scroll? Would you simply want to not allow the user to expand any items in the tree ? And not allow any checklistbox items to be 'checked'? This would be as simple as binding an event to those actions and if your "freeze" is active veto the events.
You should use strptime to translate the time into a time structure. This works exactly like strftime only backwards.. you supply it with the format that the time will appear in and it will give you a time struct instead of giving it a time struct and telling the function how to format the output!
An example:
>>> import time
>>> my_time = '2008-7-21'
>>> time.strptime( my_time, '%Y-%m-%d' )
(2008, 7, 21, 0, 0, 0, 0, 203, -1)
>>> new_time = time.strptime( my_time, '%Y-%m-%d' )
>>> time.strftime( '%y%m%d', new_time )
'080721'
>>>
Refer to this page for more information on the time formatting strings for strftime and strptime.
It's not exactly possible to have an assignment triggered off of the modification of another object without actually monitoring it with a timer function or something that is running in the background but what if you used a function to set both of the names to the same thing like this:
>>> class item:
... def __init__( self, name = None ):
... self.name = name
... self.creationName = name
... def changeName( self, new_name ):
... self.name = new_name
... self.creationName = new_name
...
>>> itemInst = item()
>>> itemInst.changeName( 'An item' )
>>> itemInst.name
'An item'
>>> itemInst.creationName
'An item'
>>> itemInst.changeName( 'Different name' )
>>> itemInst.name
'Different name'
>>> itemInst.creationName
'Different name'
>>>
Strip takes away all trailing and leading whitespace. It will always remove newline characters and carriage returns (\n on linux and \r\n on windows), and it will always remove excess spaces and tabs at the beginning and end of the text.
For your other question yes, spaces, tabs, even newlines are considered a single character and will be taken into account when using slicing.
Here's your code with the strip statement. And also you do not have to use another %s for entering a newline into your text. Read up on string formatting a little bit here, as I'll make a slight modification to that statement...
inp = open('C:\\Documents and Settings\\Lev.DEEPBLUE\\Desktop\\halfSA.txt', 'r')
outp = open('C:\\Documents and Settings\\Lev.DEEPBLUE\\Desktop\\halfSA2.txt', 'w')
for eachline in inp:
eachline = eachline.strip()
# You could alternately do line_data = eachline.strip().split(), which does the same thing
line_data = eachline.split()
if eachline[:2] == 'MM' or eachline[:2] == 'HS':
outp.write( '%s %s\n' % ( line_data[1], line_data[2] ) )
inp.close()
outp.close()