Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I am try to run this program as it start run but while running it's create error regrading CatchAllError . I want output as ' Pass ' But its not please help. Thanks
if line:
msg = url.strip()+' - CatchAllError'
print msg
with open("log_Error.txt", "a") as log:
log.write(msg+"\n")
else:
pass
You can see my whole program at https://ghostbin.com/paste/ypdmd.
You can see that if condition should be pass but it's not. To include target list go to https://ghostbin.com/paste/pjuox and download target list and other information.
You are mixing tabs and spaces. This confuses Python* and may cause unexpected behavior.
Use only tabs or only spaces, not both. Spaces is preferable.
(*well, not really. Python knows exactly how to handle tabs; it just does so in a way that is very surprising to most users. In particular, one tab is not equivalent to 4 spaces, or 8, or whatever it looks like in your text editor. See 2.1.8 - Indentation for more information.)
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I'm hoping this is a simple stupid problem. But we have an in-house program that is no longer working. The program is not able to pass the data which is supposed to be contained in a variable using var_name+="".
The variable seemingly contains nothing. when I try to print the contents of this variable to either a string or text doc, we get nothing. The variable in question here is "allData".
The contents of this variable need to be passed to our fax appliance.
def sendFax(destOrg, destFax, cliName, casenum, attachments, errEAddr, comment, destName):
creds=requests.auth.HTTPBasicAuth(user,password)
#OVERRIDE OUTBOUND FAX NUMBER FOR TESTING
destFax='716-631-9804'
print("faxes will be sent to "+destFax)
return
allData=''
allData+='<schedule_fax>\n'
allData+='<cover_page>\n'
allData+='<url>'+prepXMLString(coverPage)+'</url>\n'
allData+='<enabled>true</enabled>\n'
allData+='<subject>'+prepXMLString(cliName)+' - case # '+str(casenum)+'</subject>\n'
allData+='<comments>'+prepXMLString(comment)+'</comments>\n'
allData+='</cover_page>\n'
allData+='<sender>\n'
allData+='<name>'+prepXMLString(webAddr)+'</name>\n'
allData+='<organization>'+prepXMLString(ourOrg)+'</organization>\n'
allData+='<phone_number>'+prepXMLString(ourPhonenum)+'</phone_number>\n'
allData+='<fax_number>'+prepXMLString(ourFaxnum)+'</fax_number>\n'
allData+='<email_address>'+prepXMLString(errEAddr)+'</email_address>\n'
allData+='</sender>\n'
allData+='<recipient>\n'
allData+='<name>'+prepXMLString(destName)+'</name>\n'
allData+='<organization>'+prepXMLString(destOrg)+'</organization>\n'
allData+='<fax_number>'+destFax+'</fax_number>\n'
allData+='</recipient>\n'
That is all screwed up. You're returning on the line with the return keyword which is why nothing is being returned.
You should do all of the concatenation and then return.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I've got an issue where my regex isn't parsing the output of a file I created:
#!/usr/bin/env python3
import wget, re
url=''
filename=wget.download(url)
with open ('Output.txt', "r") as f:
readlines=f.read()
ret=re.sub("^.*\^", "", readlines)
print(ret)
According to this site, the regex I'm using "^.*\^" is valid for my output. Sample output I'm feeding it is something like this:
1212-2010^readthispart
Where it has a carot for a delimiter. I tried double and single quotes to no avail and I'm not sure if it's an issue elsewhere in my code or what, but the printout does not match what I'm looking for. Ideas?
If I'm reading your question and edits right you're looking to return 'readthispart', correct? If so you need to look into using look-behinds in combination with search. See https://docs.python.org/2/library/re.html. re.search("(?<=\^).*",myinput)
You need to enable multiline mode:
re.sub('^.*\^', '', readlines, flags=re.MULTILINE)
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
Here is what I currently have, which is not working:
if "Forwarder" not in shp_name or "T_" not in shp_name or "Grad" not in shp_name:
I've also tried:
if ("Forwarder", "T_", "Grad") not in shp_name:
Samples of the input would be "DS_Forwarder_1" or "DS_Harvester_1". The script proceeds directly to else as it's unable to identify any of the above substrings in the primary string.
Try using the any built in.
if any(s in shp_name for s in ("Forwarder", "T_", "Grad")):
...
This will be true if any of the given strings are present in shp_name. You can use if not any(... if you want False when one of the strings is present.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am new to python and trying to learn an unfamilar code base. I want to add a print statement just below the def line. But every time I do so for one of these very short methods I get an indentation error.
def rename(self, old, new):
#print 'this will bring an error if left uncommented'
return os.rename(self._full_path(old), self._full_path(new))
How can I add a print statement to a short method like this?
A tab is a tab character (just like \n is a newline character), you can configure most editors to replace a tab character with a certain number of spaces.
The convention in Python is to indent by four spaces and to use spaces instead of tabs. This is the recommendation; but people tend to do what they please.
It is most likely that the code is indented by tabs and you are using spaces. #TimPeters wrote reindent.py that will take a Python file and convert tabs into spaces.
There are other tools as well. Most editors have a function that can do this, if the editor is Python aware they may have a specific function for just this. For example pycharm has a "Convert Indents" menu option under Edit.
Try this code:
def rename(self, old, new):
print('this will bring an error if left uncommented')
return os.rename(self._full_path(old), self._full_path(new))
Whenever I have trouble with the print keyword, I can usually solve it by using print() instead.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
the following problem in python please .....
Assuming that s is a string of lower case characters.
how would I write a program that prints the number of times the string 'bob' occurs in s. For example, if s = 'azcbobobegghakl', then my program would print
'Number of times bob occurs is: 2'
I am a completely new to python and appreciate any help
If you didn't want to count overlapping bobs as separate values, this would be easy:
s.count('bob')
But you apparently do. (I had to guess that, based on the fact that your intended output is 2 rather than 1… in the future, it would be better to explain your problem instead of leaving it ambiguous.) As the help says, count returns "the number of non-overlapping occurrences of substring sub…", so that won't do any good.
So, for that, you will have to do it manually. I'll show an example that should have enough to get you started:
for i in range(len(s)):
if s[i:].startswith('bob'):
print('Found a bob')
A slightly smarter way to do this would be to use the find method on strings. You can find details on this in the online docs, or by typing help(str.find) in the interactive console. Notice that find takes a start argument. You should be able to figure out how this would help you; it may take a bit of work to get the details right, but if you get stuck, you can always post a new question asking for specific help.
You can try this way
string = "BOBOBOBOBOABCDE"
search = "BOB"
print len([i for i in range(len(string)) if string.startswith(search, i)])