This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
with open('input.csv', 'r') as in_file, open('output.csv', 'w') as out_file: | |
reader = csv.reader(in_file) | |
writer = csv.writer(out_file) | |
header = next(reader) # remember and then skip header | |
print(header) | |
writer.writerow(header) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
I have about 200 database migration files in a single flat directory | |
that I need to have sorted and renamed. The files are in pairs and named | |
in a format like : | |
0023_xyz.up.sql | |
0023_xyz.down.sql | |
There are always four numerical characters before the first underscore, | |
and they are always left-padded with zeroes. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
I need a script that will look at all the files in a directory (example below),\ | |
and move all of those that contain a selected set of words (like "Cal.App.2d")\ | |
into a new sub-directory with that name. | |
""" | |
import os | |
import shutil | |
def mover(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.utils.deprecation import MiddlewareMixin | |
class ForceDefaultLanguageMiddleware(MiddlewareMixin): | |
""" | |
Ignore Accept-Language HTTP headers | |
This will force the I18N machinery to always choose settings.LANGUAGE_CODE | |
as the default initial language, unless another one is set via sessions or cookies | |
Should be installed *before* any middleware that checks request.META['HTTP_ACCEPT_LANGUAGE'], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pprint | |
import requests | |
url = 'https://api.vk.com/method/wall.get?&owner_id=-50485628&count=5' | |
posts = requests.get(url).json() | |
posts = posts['response'][1:] # Отсекаем все ненужное, оставляя только посты | |
print([post['likes']['count'] for post in posts]) # Просто вывод списка лайков |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
https://ru.wikipedia.org/wiki/%D0%A0%D0%B5%D1%88%D0%B5%D1%82%D0%BE_\ | |
%D0%AD%D1%80%D0%B0%D1%82%D0%BE%D1%81%D1%84%D0%B5%D0%BD%D0%B0 | |
''' | |
def sieve(): | |
x = [i for i in range(2,100)] | |
primes = [] | |
while x: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main_list = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] | |
result_list = [] | |
for i in range(0, len(main_list), 4): | |
item = main_list[i:i+4] # Делаем слайс в 4 элемента | |
item = ' (s) '.join(item) + ' (s)' # Объединяем его в строку c разделителями | |
result_list.append(item) | |
print(result_list) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
1) it get a full path as a parameter | |
C:\\Users\\John\\Documents\\appname\\0f4f46908f3a15a40eb09b4fdb6efd8259c6b0d2\\ | |
3) scan a subfolders in a path | |
4) determine a folder with name that contains most new date | |
5) remember it as a variable and exit | |
its better to create a function inside a code that makes it getNewwestFolder(path) | |
Example of subfolders names: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form id="post_form" method="post" action='/toggle/'>{% csrf_token %} | |
<input type="submit" value="Toggle"> | |
</form> | |
<div id="toggle"></div> |