I have code that manipulates data of a file that I currently have hard-coded in the script.  I want to be able to prompt the user to chose the input file rather than having to hard-code it.  Here is what I have for input.  Instead of always using myfile.txt, I'd like the user to be able to choose the file:  with open('myfile.txt', 'rU') as input_file:
1878
How do I have a Python script that a) can accept user input and how do I make it b) read in arguments if run from the command line?
71532
After hitting ⌘-O, how can I navigate my folders and select a file to open using only my keyboard?   In particular, how can I get the focus into the folder list? (From there I can use arrows or start typing the first letters of the desired file/folder.)  In some programs I can rely on hitting TAB 5 times, but this isn't reliable and I figure there must be a better way.
2601
I want to pause input in a shell script, and prompt the user for choices. The standard Yes, No, or Cancel type question. How do I accomplish this in a typical bash prompt?
69828
This is my file1:    #$BQ #{ VOL       @home    } #database    daba #relation    tcdeatid #copy           1 #{ version        0 } #opendb #clear #.lruno := 72 #.infno := 1 #.tid.noel := 101 #.tid.info := 64 #.tid.setnr := 1225              &lt;--- (1225 number will be changed) #.typeidm := 1 #.sourcetable := 2 #writedb      #clear #.lruno := 72 #.infno := 205 #.tid.noel := 101 #.tid.info := 76 #.tid.setnr := 5625              &lt;--- (5625 number will be changed) #.typeidm := 1 #.sourcetable := 2 #writedb #$EOJ  In file2, I have the correct entries:    #.tid.info := 3345              &lt;--- (I want to put this number in file1 in place of 64) #.tid.setnr := 1254              &lt;--- (I want to put this number in file1 in place of 1225) #.tid.info := 5567              &lt;--- (I want to put this number in file1 in place of 76) #.tid.setnr := 9056              &lt;--- (I want to put this number in file1 in place of 5625)   I want to make changes in file1, directed by data from file2.  I have tried sed "s/tid.setnr := 1225/tid.setnr := 1254/g" file1 &gt; modified_file1  But instead of doing it manually, I want my script to read the new tid.info and tid.setnr values from file2 and modify the respective lines in file1.  The first line in file2 should replace the entire first line in file1 that contains tid.info, the second line in file2 should replace the second line in file1 that contains tid.setnr, and so on.
9216
I want to prompt for user input after all parameters have been specified for the script tool. I've seen many forum posts and stackexchange questions about this, and they all conclude that it's unnecessary, but I think my case is an exception. I want to give the user an opportunity to confirm data, such as how many sets of GPS coordinates there are. They will be yes/no questions ("is this data obviously incorrect?"), and the script tool parameter input form doesn't seem like it'd work well for this.  I know Tkinter's event handler causes problems with ArcGIS, and other framworks have similar problems. One workaround I found is to have your script call another script that runs as a separate process, and display the GUI from the second process, but that seems a little too hackish.    Apparently wxPython does work, but it's not included with python. I need to be able to distribute these scripts without any extra requirements other than ArcGIS, so that wouldn't work for me.    To clarify, the most important use would be to prompt the user when my software validation checks can't validate the data. For example, I have a list of IDs that I want to validate, but the format isn't consistent. I want to be able to prompt the user with a yes/no dialog if I can't validate in software (eg. the ID doesn't match one of the common patterns). It's possible that new ID formats will be created without my knowledge.    Another example: I have a file that contains, among other things, a table of start &amp; stop times. I want to validate each row of the table individually, and cramming all of that data, plus the other checks, into the warning window would get ugly fast.
9012
I'd like to make a click event fire on an &lt;input type="file"&gt; tag programmatically.  Just calling click() doesn't seem to do anything or at least it doesn't pop up a file selection dialog.  I've been experimenting with capturing events using listeners and redirecting the event, but I haven't been able to get that to actually perform the event like someone clicked on it.
62543
I have a .txt that can be exemplified like this:  NAME | CODE name1 | 001 name2 | 001 name3 | 002 name4 | 003 name5 | 003 name6 | 003   I need to write a script to split this file according to the CODE column, so in this case I'd get this:  file 1: NAME | CODE name1 | 001 name2 | 001  file 2: NAME | CODE name3 | 002  file 3: NAME | CODE name4 | 003 name5 | 003 name6 | 003   According to some research, using awk would work:  $ awk -F, '{print &gt; $2".txt"}' inputfile   The thing is, I also need to include the header to the first line and I need the file names to be different. Instead of 001.txt, for example, I need the file name to be something like FILE_$FILENAME_IDK.txt.
104748
Right now I'm using echo &quot;Hello World&quot; &gt;&gt; file.txt  to append some text to a file but I also need to add text below a certain string let's say [option], is it possible with sed? EG: Input file Some text Random [option] Some stuff  Output file Some text Random [option] *inserted text* Some stuff
19556
Yes,  but there must be a canonical or most efficient or most concise way. I'll add answers I know of and see what percolates to the top.  To be clear, the question is how best to read the contents of a file into a string. One solution per answer.
94156
Open a prompt, try to do this:   type this code: export PS1="\e[1;30m-30-\e[m &gt;" copy it with your mouse (select the code + copy it (I have auto-copy when I select with the mouse enabled)) close the prompt open a brand new prompt immediately paste it (SHIFT INS) type "HOME" key and "END" key, you'll see the cursor go to logical positions (start and end of the code) now press ENTER you prompt changes the colors immediately paste it (SHIFT INS) type "HOME" key and "END" key, you'll see the cursor go to illogical positions (offset problem)   This means if I apply colors to the prompt I can't copy/paste + change my copied code...   NB: I'm asking it here because I thought it was a problem of  but it seems it's only related to what I'm trying to assign: export PS1="\e[1;30m-30-\e[m &gt;"... and I dont see a problem. It should just change the colors of the prompt (and that's what it does actually). But it seems it does something more I dont see. Does somebody know what it could be?
81419
Is it possible to use the =today() function (or something else) to insert the current date but then not update each time the file is opened?  I want to create a numbers template for my invoices. I'd like it to auto fill invoice date and date due then, when I save the document, store the values, not the function.
82863
How can I insert some text in specific lines of a file? What is the simplest method that I can use? (bash, sed, awk?) What I want to do might be simple, but I don't know where I should start. It takes too much time for me to try to do this manually (I have a lot of files that I have to change for Excel/Calc later use). Here is my input file example: 4.06 4.05 5.04 4.06 34.50 56.06 45.33 36.44  And I want something like this (insert text before line 1 and 5): Exp1     4.06 4.05 5.04 4.06 Exp2 34.50 56.06 45.33 36.44  How can I do this?
53727
I'm building a small web app in PHP that stores some information in a plain text file. However, this text file is used/modified by all users of my app at some given point in time and possible at the same time.  So the questions is. What would be the best way to make sure that only one user can make changes to the file at any given point in time?
18786
I need to lock a file for writing in Python. It will be accessed from multiple Python processes at once. I have found some solutions online, but most fail for my purposes as they are often only Unix based or Windows based.
3334
I am writing a batch file script using Windows command-line environment and want to change each occurrence of some text in a file (ex. "FOO") with another (ex. "BAR"). What is the simplest way to do that? Any built in functions?
77902
I have a small text file that I'd like to read into a scalar variable exactly as it is in the file (preserving line separators and other whitespace).  The equivalent in Python would be something like  buffer = ""  try:     file = open("fileName", 'rU')     try:         buffer += file.read()     finally:         file.close() except IOError:     buffer += "The file could not be opened."   This is for simply redisplaying the contents of the file on a web page, which is why my error message is going into my file buffer.
85719
I want to output a file's contents while they change, for example if I have the file foobar and I do:  magic_command foobar  The current terminal should display the file's contents and wait until, I don't know, I press ^C.  Then if from another terminal I do:  echo asdf &gt;&gt; foobar  The first terminal should display the newly added line in addition to the original file contents (of course, given that I didn't press ^C).