How do i ignore the space in command line input in python

So i need to append to a file in python. This is a random command line input

Example 1:

file1 This is a sentence.

How do i make it so it "This is a sentence" would be appended to file1 not just "This"

Example 2:

file2 A sentence

How do i make it so it "A sentence" would be appended to file2 not just "A"

This is what i have so far. And any random sentence could be appended to the files

with open(input[1],'a') as fileA:
        fileA.write(input[2])

Answers


Pass the second command line arguments as a single argument in the shell:

python /path/to/script.py file1 "This is a sentence."

Alternatively, join the arguments after the filename using str.join:

with open(input[1], 'a') as fileA:
    fileA.write(' '.join(input[2:]))

But the alternative solution will not preserve exact count of spaces / tabs.


Need Your Help

What is the best way to connect between python dict and PyQt widget?

python pyqt pyside

I have a giant dict with thousands of keys, and some of that keys also are giant dicts, and so on.

Need help CSS class referring to markup-tag

html css css-selectors html-table

I'm working with Vaadin, a GWT like framework for developing rich web applications.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.