Python Tutorial
total = item_one + \ item_two + \ item_three
source_file = os.path.join(config_directory, "temp_dir", "file1.txt")Example:
#!/usr/bin/python import os config_directory = "test/"; source_file = os.path.join(config_directory, "file1.txt") dest_file = os.path.join(config_directory, "file2.txt") def get_file_data(file_name): if not os.path.exists(file_name): return '' try: with open(file_name, 'r') as f: return f.read() except IOError: print("Error reading file: " "%s" % file_name); return '' file_data = get_file_data(source_file) + "\n" + \ "New line in code"; with open(dest_file, 'w') as df: df.write(file_data); os.chmod(dest_file, 0o600);Output:
$ python test_file_write.py $ cat test/file2.txt line1 line2 New line in code
list_var = ['one', 'two', 'three', 'four', 'five'];Example:
#!/usr/bin/python list_var = ['one', 'two', 'three', 'four', 'five']; list_var.append('six'); new_list_var = ['seven', 'eight']; list_var.extend(new_list_var); print list_var;Output:
$ python test_array.py ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight']
import sys;sys.exit();
a = b = c = 1
a, b, c = 1, 2, "test"
Python Tutorial
Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us
| Report website issues in Github
| Facebook page
| Google+ page