Menu
Menu
DaniWeb
Log In
Sign Up
Read
Contribute
Meet
Search
Search
About 410 results for
fileinput
- Page 1
fileinput confusion :(
Programming
Software Development
13 Years Ago
by Skrell
…i get at the command prompt. PLEASE help. [CODE] import
fileinput
, sys, string, os def main(): searchterm = sys.argv[1…;removed" else: print item print targetdir for line in
fileinput
.input(targetdir): num_matches = string.count(line, searchterm) if num_matches:…
Re: Fileinput from files ignoring incorrect ones.
Programming
Software Development
13 Years Ago
by TrustyTony
What you catched from
fileinput
documentation?
Re: Fileinput from files ignoring incorrect ones.
Programming
Software Development
13 Years Ago
by TrustyTony
… with bunch of Python files as arguments. You did read
fileinput
documentation? I use the mention that empty files are opened…
(newb) fileinput.input IOError handling
Programming
Software Development
13 Years Ago
by Skrell
I am trying to use the
fileinput
.input() module to read in the lines from a bunch … items in the list i'm feeding
fileinput
,input() generates this IOError, i can get
fileinput
to simply continue onto the next…
Re: (newb) fileinput.input IOError handling
Programming
Software Development
13 Years Ago
by Skrell
…work. Here is my code: [CODE] try: for line in
fileinput
.input(newlist): num_matches = string.count(line, searchterm) if num_matches:… %s on line %d." % (searchterm, num_matches,
fileinput
.filename(),
fileinput
.filelineno()) except IOError: print "There was a problem with…
Re: (newb) fileinput.input IOError handling
Programming
Software Development
13 Years Ago
by TrustyTony
You must put try around the
fileinput
that is in try to line "5.5" and indent the print line and 7 to same level as try: (current print indention).
Re: (newb) fileinput.input IOError handling
Programming
Software Development
13 Years Ago
by TrustyTony
Actually I did not realize you are using
fileinput
as iterator already in for line. To get hat to work I think you must wrap it in function passing IOErrors. string.count is not also good style, you should use the method of string itself: "abcd".count("a")
Re: fileinput confusion :(
Programming
Software Development
13 Years Ago
by Gribouillis
The issue with your txt file filter is that you are removing items in targetdir while iterating on targetdir. This does not work. Look at this example [code=python] >>> L = range(20) >>> for item in L: ... print item, ... if item % 3: ... L.remove(item) # DONT DO THAT !!!! ... 0 1 3 4 6 7 9 10 12 13 15 16 18 19 # not all …
Re: fileinput confusion :(
Programming
Software Development
13 Years Ago
by Skrell
Ok using your suggestion i got everything to work and the traceback error no longer happens. (I dont even know what traceback means) I realize that scripts like this one already exist but i'm trying to learn on my own and since you've already taught me quite a bit my plan is working! How can i give the command line a directory without typing …
Re: fileinput confusion :(
Programming
Software Development
13 Years Ago
by snippsat
[QUOTE](I dont even know what traceback means[/QUOTE] Traceback you get when something goes wrong. [CODE]>>> a Traceback (most recent call last): File "<interactive input>", line 1, in <module> NameError: name 'a' is not defined >>> # We most define a >>> a = 5 >>> a + '6' Traceback (most …
Re: fileinput confusion :(
Programming
Software Development
13 Years Ago
by Skrell
r'C:\' does not work on the command line : [CODE]Traceback (most recent call last): File "mygrep.py", line 35, in <module> main() File "mygrep.py", line 21, in main file = os.listdir(sys.argv[2]) WindowsError: [Error 3] The system cannot find the path specified: 'rC:"/*.*' [/CODE] Also, how could i make…
Re: fileinput confusion :(
Programming
Software Development
13 Years Ago
by TrustyTony
r'C:\*.*' not inside the quotes. See [url]http://www.tutorialspoint.com/python/python_strings.htm[/url] for all about strings.
Re: fileinput confusion :(
Programming
Software Development
13 Years Ago
by Skrell
I didn't put it in the quotes i literally typed r'C:\' which then makes things even more confusing because as you can see in the error message it draws the r inside the quotes??
Re: fileinput confusion :(
Programming
Software Development
13 Years Ago
by TrustyTony
But you did that in Python code, not in Command interpreter, which is alltogether different thing? sys.argv[2] refers to command line, which gives \ directly without quotes entered even (but double quotes can be used in command line, not Python single quotes of course). [CODE]import sys print sys.argv[1] if sys.argv[1:] else 'No arguments given'[/…
FileInput/Output Stream on JTextField
Programming
Software Development
14 Years Ago
by cathgodarve
[TEX]hey there, can you help me with something. I'm supposed to get data from a single text file and use it on 3 different jTextField. Then if I hit a save button, the data from the textfields will overwrite the existing data of the text file. Unfortunately, I can't make, and instead I used 3 text file. How can I get data from 1 text file? Please …
Re: FileInput/Output Stream on JTextField
Programming
Software Development
14 Years Ago
by javaAddict
What errors do you get. In the catch print the exception that you get in order to know what went wrong. That message means nothing: System.out.println("Error in file") [CODE] catch (Exception e) { System.out.println("Error: "+e.getMessage()); // or less elegant e.printStackTrace(); } [/CODE]
Fileinput from files ignoring incorrect ones.
Programming
Software Development
13 Years Ago
by TrustyTony
Learned about hook functions [URL="http://www.daniweb.com/software-development/python/threads/383164/1650339#post1650339"]for a thread[/URL] having problem with bad user input from the documentation. This is result which skips bad inputs.
Re: Fileinput from files ignoring incorrect ones.
Programming
Software Development
13 Years Ago
by TrustyTony
Actually the line 15, while does not disturb, does nothing, as it is from before I realized I must always return file object. So it should be removed and rest of the function unindented for clean code.
Re: Fileinput from files ignoring incorrect ones.
Programming
Software Development
13 Years Ago
by Skrell
Ok now that i've found your code, as I am a newb, would you mind explaining the openhook concept a bit as i don't full grasp it?
Re: Fileinput from files ignoring incorrect ones.
Programming
Software Development
13 Years Ago
by Skrell
What does process('=') do ? And what does opening a 'dummy' file accomplish? Does it allow the function to continue by replacing the unreadable file with a dummy one that IS readable ?
Re: (newb) fileinput.input IOError handling
Programming
Software Development
13 Years Ago
by snippsat
When you get IOError,pass make it countinue to end. Other errors than IOError will raise error as normal. [CODE]try: doSomething() except IOError: pass[/CODE]
Re: (newb) fileinput.input IOError handling
Programming
Software Development
13 Years Ago
by Skrell
I'm sorry i don't follow :(
Re: (newb) fileinput.input IOError handling
Programming
Software Development
13 Years Ago
by TrustyTony
After looking the documentation it appears that you can give hook function to method, which can ignore the ioerrors.
Re: (newb) fileinput.input IOError handling
Programming
Software Development
13 Years Ago
by Skrell
[QUOTE=pyTony;1650365]After looking the documentation it appears that you can give hook function to method, which can ignore the ioerrors.[/QUOTE] ??
Re: (newb) fileinput.input IOError handling
Programming
Software Development
13 Years Ago
by TrustyTony
I posted code snippet how to do it.
Re: (newb) fileinput.input IOError handling
Programming
Software Development
13 Years Ago
by Skrell
[QUOTE=pyTony;1650577]I posted code snippet how to do it.[/QUOTE] Perhaps i'm losing my mind, but where did you post this code snippet? I don't see it :(
Re: (newb) fileinput.input IOError handling
Programming
Software Development
13 Years Ago
by TrustyTony
Look code snippet part of the forum. It would maybe be usefull to read my post linked from my signature.
Array Calculations
Programming
Software Development
15 Years Ago
by ThomasII
…(","c) tran.TransactionDate =
fileInput
(0) tran.DepoOrWith =
fileInput
(1) tran.TransactionAmount =
fileInput
(2) tran.PreviousBalance =
fileInput
(3) ReDim Preserve m_transSet(x) m_transSet…
The class returns an error message
Programming
Software Development
15 Years Ago
by puppykillaz
…(","c) tran.TransactionDate =
fileInput
(0) tran.DepoOrWith =
fileInput
(1) tran.TransactionAmount =
fileInput
(2) tran.PreviousBalance =
fileInput
(3) ReDim Preserve m_transSet(x) m_transSet…
Re: The class returns an error message
Programming
Software Development
15 Years Ago
by puppykillaz
….Split(","c) tran.TransactionDate =
fileInput
(0) tran.DepoOrWith =
fileInput
(1) tran.TransactionAmount =
fileInput
(2) tran.PreviousBalance =
fileInput
(3) m_transSet(x) = tran listDisplay…
1
2
3
7
Next
Last
Search
Search
Forums
Forum Index
Hardware/Software
Recommended Topics
Programming
Recommended Topics
Digital Media
Recommended Topics
Community Center
Recommended Topics
Latest Content
Newest Topics
Latest Topics
Latest Posts
Latest Comments
Top Tags
Topics Feed
Social
Top Members
Meet People
Community Functions
DaniWeb Premium
Newsletter Archive
Markdown Syntax
Community Rules
Developer APIs
Connect API
Forum API Docs
Tools
Backlink Auditor
Legal
Terms of Service
Privacy Policy
FAQ
About Us
Advertise
Contact Us
© 2025 DaniWeb® LLC