def load_files(file_names): """Loads all files into the database. file_names : str All the file names to load into the database """ for file_name in file_names: print() print("Loading file {0}".format(file_name)) f.debug("Opening file handler for '{0}'".format(file_name)) with f.open_file(file_name) as file: try: read_and_load_file(file) print("File loaded.") except StopIteration: print("File is empty: {0}".format(file_name)) except Exception as err: f.error("Error while loading file into table: {0}".format( file.name)) exception, traceback = f.get_exception_details() f.error(exception) f.debug(traceback) cfg.data_loading_error = True print("Skipping file.") print()
def test_pipe_separated_file(self): cfg.column_separator = "|" with f.open_file("../resources/201812-citibike-tripdata.psv") as file: reader = f.get_csv_reader(file) content = [f.read_header(reader)] for line in reader: content.append(line) self.assertEqual(len(content), 11)
def open_file(self): """打开选择的文件并显示""" self.file_path = fc.open_file() print(self.file_path) self.file_entry.delete(0, END) self.file_entry.insert(END, self.file_path) self.show_img = fc.modify_img(self.file_path, 680, 400) self.img_label['image'] = self.show_img
def test_tab_separated_file(self): print("test_tab_separated_file") cfg.column_separator = "\t" with f.open_file("../resources/201812-citibike-tripdata.tsv") as file: reader = f.get_csv_reader(file) content = [f.read_header(reader)] for line in reader: content.append(line) self.assertEqual(11, len(content))
def test_raw_input_to_lit(self): with f.open_file("../resources/201811-citibike-tripdata.csv") as file: self.assertEqual(f.raw_input_to_list(file.readline()), [ "tripduration", "starttime", "stoptime", "start station id", "start station name", "start station latitude", "start station longitude", "end station id", "end station name", "end station latitude", "end station longitude", "bikeid", "usertype", "birth year", "gender" ])
def test_read_header(self): with f.open_file("../resources/201811-citibike-tripdata.csv.gz") as file: reader = f.get_csv_reader(file) expected = ["BIKEID", "BIRTH_YEAR", "END_STATION_ID", "END_STATION_LATITUDE", "END_STATION_LONGITUDE", "END_STATION_NAME", "GENDER", "STARTTIME", "START_STATION_ID", "START_STATION_LATITUDE", "START_STATION_LONGITUDE", "START_STATION_NAME", "STOPTIME", "TRIPDURATION", "USERTYPE"] expected.sort() actual = f.read_header(reader) actual.sort() self.assertListEqual(actual, expected)
def test_read_header(self): with f.open_file( "../resources/201811-citibike-tripdata.csv.gz") as file: self.assertEqual( f.read_header(file), { "BIKEID", "BIRTH_YEAR", "END_STATION_ID", "END_STATION_LATITUDE", "END_STATION_LONGITUDE", "END_STATION_NAME", "GENDER", "STARTTIME", "START_STATION_ID", "START_STATION_LATITUDE", "START_STATION_LONGITUDE", "START_STATION_NAME", "STOPTIME", "TRIPDURATION", "USERTYPE" })
def load_files(file_names): """Loads all files into the database. file_names : str All the file names to load into the database """ for file_name in file_names: print() print("Loading file {0}".format(file_name)) f.debug("Opening file handler for '{0}'".format(file_name)) with f.open_file(file_name) as file: read_and_load_file(file) print("Done") print()
def generate_table_sql(file_names, column_data_type): """Generates SQL for the table to load data. Parameters ---------- file_names : str The file_names to scan for columns column_data_type : str The column data type to use """ col_set = set() for file_name in file_names: file = f.open_file(file_name) columns_to_add = f.read_header(file) col_set = add_to_col_set(col_set, columns_to_add) file.close() print_table_and_col_set(col_set, column_data_type)
def generate_table_sql(file_names, column_data_type): """Generates SQL for the table to load data. Parameters ---------- file_names : str The file_names to scan for columns column_data_type : str The column data type to use """ col_list = [] for file_name in file_names: f.debug("Reading file {0}".format(file_name)) with f.open_file(file_name) as file: reader = f.get_csv_reader(file) columns_to_add = f.read_header(reader) f.debug("Columns to add {0}".format(columns_to_add)) # Add columns to list implicitly removing duplicates for when going over multiple files col_list.extend(col for col in columns_to_add if col not in col_list) print_table_and_columns(col_list, column_data_type)
def open_file2(self): self.file2_path = fc.open_file() self.file2_entry.delete(0, END) self.file2_entry.insert(END, self.file2_path) self.show_img2 = fc.modify_img(self.file2_path, 485, 400) self.img2_label['image'] = self.show_img2
def __init__(self, parent=None): QtWidgets.QWidget.__init__(self, parent) # objects self.hcr_tcp_server = None self.grc_tcp_server = None self.sender_lib_thread = None # setup UI self.ui = Ui_Dialog() self.ui.setupUi(self) # 设置状态指示灯控件 self.LED_sender = LedIndicator(self) self.ui.horizontalLayout_Sender.addWidget(self.LED_sender) self.LED_sender.setFixedSize(20, 20) self.LED_sender.setDisabled(True) # 禁止手动更改状态 self.LED_GRC = LedIndicator(self) self.ui.horizontalLayout_GRC.addWidget(self.LED_GRC) self.LED_GRC.setFixedSize(20, 20) self.LED_GRC.setDisabled(True) # 禁止手动更改状态 self.load_ini() # 设置禁止更改窗口大小 self.setFixedSize(self.width(), self.height()) # 设置只显示关闭按钮 self.setWindowFlags(QtCore.Qt.WindowCloseButtonHint) # child windows self.status_window = StatusForm() self.status_window.show() # a timer to update status self.timer = QTimer(self) # 初始化一个定时器 self.timer.timeout.connect(self.timer_click) # 计时结束调用operate()方法 self.timer.start(500) # 设置计时间隔500ms并启动 # Setup console output, emmit stdout sys.stdout = EmittingStream(textWritten=self.normal_output_written) # button functions self.ui.open_file_button.clicked.connect( lambda: functions.open_file(self)) self.ui.server_button.clicked.connect(self.start_stop_server) self.ui.send_button.clicked.connect(self.sending) self.ui.reset_sys_btn.clicked.connect( lambda: cmd_function.cmd_reset(self)) self.ui.set_mode_btn.clicked.connect( lambda: cmd_function.cmd_set_mod(self)) self.ui.set_file_no_btn.clicked.connect( lambda: cmd_function.cmd_set_pre_file(self)) self.ui.del_file_btn.clicked.connect( lambda: cmd_function.cmd_del_file(self)) self.ui.set_nid_btn.clicked.connect( lambda: cmd_function.cmd_set_nid(self)) self.ui.FTP_start_btn.clicked.connect( lambda: cmd_function.cmd_ftp_start(self)) self.ui.FTP_stop_btn.clicked.connect( lambda: cmd_function.cmd_ftp_stop(self)) self.ui.set_seed_btn.clicked.connect( lambda: cmd_function.cmd_set_seed(self)) self.ui.down_file_block_btn_4.clicked.connect( lambda: cmd_function.cmd_get_file_block(self)) self.ui.set_ant_btn_3.clicked.connect( lambda: cmd_function.cmd_switch_antenna(self)) self.ui.down_gongcan_btn.clicked.connect( lambda: cmd_function.cmd_get_status(self)) self.ui.set_speed_btn.clicked.connect( lambda: cmd_function.cmd_set_speed(self)) self.ui.set_sat_block.clicked.connect( lambda: cmd_function.cmd_set_sat_block_num(self)) self.ui.rf_gongcan_btn.clicked.connect( lambda: cmd_function.cmd_gongcan_download_time(self)) self.ui.set_hex_btn.clicked.connect( lambda: cmd_function.cmd_send_hex(self)) self.ui.pushButton_childwindow.clicked.connect(self.status_window.show) # comboBox functions self.ui.comboBox.currentTextChanged.connect( lambda: functions.change_channel(self)) self.ui.cmd_channel.currentTextChanged.connect( lambda: functions.cmd_change_channel(self)) # checkbox functions self.ui.checkBox_encrypt.stateChanged.connect( lambda: functions.encrypt_status_changed(self)) # lineedit functions # self.ui.delay_us.textChanged.connect( # lambda: functions.change_timeout(self)) self.ui.craft_id.editingFinished.connect( lambda: functions.change_craft_id(self)) # GRC状态改变 self.LED_GRC.toggled.connect( lambda: self.status_window.set_signal(self.grc_tcp_server)) # 读取AES_key functions.open_aes_key(self)
def test_open_zip_file(self): print("test_open_zip_file") with f.open_file( "../resources/201811-citibike-tripdata.csv.zip") as file: self.assertIsNotNone(file.read())
from functions import open_file, cenzura0, cenzura1, cenzura2, cenzura_cont, wybór_stopnia a0 = input('Podaj tekst do ocenzurowania: ') b = open_file() # stworzenie listy wulgaryzmów a2 = a0.split(' ') while True: choice0 = input("""W jaki sposób chcesz usunąć wulgaryzmy w tekście? 0 - usunąć cały wyraz; 1 - pozostawić pierwszą literę; 2 - pozostawić pierwszą i ostatnią literę; Wybór: """) if choice0 == '0' or choice0 == '1' or choice0 == '2': result0 = wybór_stopnia(choice0, a2, b) break else: print('Podaj poprawnie wybrany stopień.') print("\n") choice = '' print(f'\nTeskt oryginalny: \n{a0}') print(f'\nTekst po naniesieniu wstępnych poprawek: \n{result0}') while True: choice = input('\nCzy chcesz poddać tekst dalszym modyfikacjom (T/N)? ') choice = choice.upper() if choice == 'T': cenzura_cont(result0) b = open_file() result0 = wybór_stopnia(choice0, a2, b) print(f'\nTekst po dodatkowych modyfikacjach: \n{result0}') elif choice == 'N':
# By: Theodore Tan #python3 # imports import sys from functions import ac_3, alpha, check_solved, open_file, setup # variables filename = sys.argv[1] # get the filename from the terminal csp = setup(open_file(filename)) # setup the csp using the data check_solved(ac_3(csp), csp) # check if the ac3 algorithm solved the problem
def add_img(self, event): """新建用户界面添加图片""" self.new_user_img_path = fc.open_file(parent=self.new_user_win) self.show_new_user_img = fc.modify_img(self.new_user_img_path, 710, 320) self.new_user_img_label['image'] = self.show_new_user_img self.new_user_img_label['text'] = ''
def test_open_gzip_file(self): with f.open_file( "../resources/201811-citibike-tripdata.csv.gz") as file: self.assertIsNotNone(file.read())