Например
p = open ("text.txt" , 'r') for line in text : a = b+c g = open(line, 'w') g.write(a)
p = open ("text.txt" , 'r') for line in text : a = b+c g = open(line, 'w') g.write(a)
lorienНе понял, можете привести пример?
используйте эту информацию чтобы построить новое имя файла, далее запишите в файл с новым именем нужные данные.
p = open ("text.txt" , 'r') for line in text : a = b+c g = open(line, 'w') g.write(a)
file_ = open ("text.txt" , 'r') for new_name_file in file_: str_to_file = "Name file is %s" % (new_name_file) vrs = open(new_name_file, 'w') vrs.write(str_to_file) vrs.close() file_.close()
vrs = open(new_name_file.rstrip(), 'w') # Убираем символ переноса строки \n
with urllib.request.urlopen(arch) as archdata,open('m.gz', 'wb') as fout: fout.write(archdata.read())
import re import urllib.request as req import urllib proxy=req.ProxyHandler({'http':r'http://**@10.5.45.250:3128'}) auth = req.HTTPBasicAuthHandler() opener = req.build_opener(proxy, auth, req.HTTPHandler) req.install_opener(opener) a = input('введите начальную дату(меньшую): ') b = input ('введите месяц меньший : ') c = input ('введите год меньший : ') a1 = input('введите дату конечную(бОльшую): ') b1 = input ('введите месяц бОльший : ') c1 = input('введите год бОльший : ') cod = open("cod.txt",'r') for m in cod: url = 'http://rp5.ru/inc/f_archive.php' dataaa='wmo_id={}&f_ed0={}&f_ed1={}&f_ed2={}&f_ed3=1&f_ed4=0&f_ed5=0&f_ed6={}&f_ed7= {}&f_ed8={}&f_pe=1&f_pe1=1&lng_id=2'.format(m,a,b,c,a1,b1,c1) script_data = dataaa.encode('latin1') with urllib.request.urlopen(url, data=script_data) as data: arch = re.findall(r'<a href=([^<]*?)>', data.read().decode('latin1'))[0] with urllib.request.urlopen(arch) as archdata,open('m.gz', 'wb') as fout: fout.write(archdata.read())
Stepe
и собственно хотелось бы что бы здесь open('m.gz', ‘wb’) - название файла было равно m.
m = 'blabla' f = open('%s.gz' % m, 'wb')
cod = open("cod.txt".rstrip(),'r') for m in cod: url = 'http://rp5.ru/inc/f_archive.php' dataaa='wmo_id={}&f_ed0={}&f_ed1={}&f_ed2={}&f_ed3=1&f_ed4=0&f_ed5=0&f_ed6={}&f_ed7= {}&f_ed8={}&f_pe=1&f_pe1=1&lng_id=2'.format(m,a,b,c,a1,b1,c1) script_data = dataaa.encode('latin1') with urllib.request.urlopen(url, data=script_data) as data: arch = re.findall(r'<a href=([^<]*?)>', data.read().decode('latin1'))[0] with urllib.request.urlopen(arch) as archdata,open('m.gz', 'wb') as fout: fout.write(archdata.read()) fout.close() os.rename('m.gz',h+'.gz')
b'wmo_id=37031\n&f_ed0=04&f_ed1=08&f_ed2=2013&f_ed3=1&f_ed4=0&f_ed5=0&f_ed6=09&f_ed7=08&f_ed8=2013&f_pe=1&f_pe1=1&lng_id=2' Traceback (most recent call last): File "C:/Python32/d", line 24, in <module> with urllib.request.urlopen(arch) as archdata,open('m.gz', 'wb') as fout: File "C:\Python32\lib\urllib\request.py", line 138, in urlopen return opener.open(url, data, timeout) File "C:\Python32\lib\urllib\request.py", line 351, in open req = Request(fullurl, data) File "C:\Python32\lib\urllib\request.py", line 194, in __init__ self._parse() File "C:\Python32\lib\urllib\request.py", line 199, in _parse raise ValueError("unknown url type: %s" % self.full_url) ValueError: unknown url type: ../objects/files.from.archive/37/37031.04.08.2013.09.08.2013.1.0.0.ru.ansi.00000000.csv.gz

m - это код региона что бы получить архив