python-3.5

Python printing function output multiple times

时光总嘲笑我的痴心妄想 提交于 2019-12-06 12:01:14
问题 I'm making a program to accomplish a certain python challenge. I created the program, and it basically does everything I need it to do, except it's got one weird quirk; it prints the output I want multiple times. cmdname = input("Enter the name of your command.\n>") print("Enter options one by one. If the option has an argument, put a * at the end of the option. When done entering options, enter \"q\".") oplist = "" oplist += cmdname + " " def prgm(): global oplist while 2 + 2 == 4: user =

Package : cx_Oracle for Python 3.5, windows64 bit. Oracle 11.2.0.1.0

拟墨画扇 提交于 2019-12-06 11:41:30
问题 I am trying to install cx_Oracle on my windows PC. I ran following command in command prompt: pip install cx_Oracle This is giving me the following error: Collecting cx-Oracle Could not find a version that satisfies the requirement cx-Oracle (from versions: ) No matching distribution found for cx-Oracle I am using windows 64bit machine and Python 3.5(Anaconda3) . Intsalled Oracle vcersion on my PC is Oracle 11.2.0.1.0 and oracle-instantclient version oracle-instantclient-11.2.0.4.0-0 Please

Python word count program from txt file

谁说胖子不能爱 提交于 2019-12-06 08:09:07
I'm trying to write a program that counts the 5 most common words in a txt file. Here is what I have so far: file = open('alice.txt') wordcount = {} for word in file.read().split(): if word not in wordcount: wordcount[word] = 1 else: wordcount[word] += 1 for k, v in wordcount.items(): print (k, v) The program as it is counts every word in the .txt file. My question is how to make it so it only counts the 5 most common words in the file so that it displays the words and the word count next to each word. One catch - I can't use dictionary...whatever that means. Easy, you just need to find the 5

Scraping: add data stored as a picture to CSV file in python 3.5

旧街凉风 提交于 2019-12-06 06:16:27
For this project, I am scraping data from a database and attempting to export this data to a spreadsheet for further analysis. (Previously posted here --thanks for the help over there reworking my code!) I previously thought that finding the winning candidate in the table could be simplified by just always selecting the first name that appears in the table, as I thought the "winners" always appeared first. However, this is not the case. Whether or not a candidate was elected is stored in the form of a picture in the first column. How would I scrape this and store it in a spreadsheet? It's

CX_Freeze executable gives “unable to load file system codec” error

别来无恙 提交于 2019-12-06 05:19:12
问题 I'm trying to get a hello world program to work with cx_freeze. It's building fine but I get errors when I run the exe: Fatal Python error: Py_Initialize: unable to load the file system codec ImportError: No module named 'encodings' My python script: if __name__ == '__main__': print('Hello World.') And my cx_freeze setup file: import sys from cx_Freeze import setup, Executable exe = Executable( script="py_helloWorld.py" ) setup( name = "helloWorld", version = "0.1", description = "Hello World

Reduce execution time on huge list generation

二次信任 提交于 2019-12-06 04:51:51
I'm fairly new to Python, and I'm trying to write some huge lists (with random letters inside). Actually it takes me around 75 - 80 seconds on my machine for 2,000,000 lines. import timeit import random, string global_tab = [] global_nb_loop = 2000000 print("Generate %d lines" % global_nb_loop) global_tab = [] for x in range(global_nb_loop): global_tab.append(("".join( [random.choice(string.ascii_letters) for i in range(15)] ), "".join( [random.choice(string.digits) for i in range(2)]))) print("%d lines generated" % len(global_tab)) And the result with linux time command: $ time python3 DEV

How to bind async method to a keystroke in Tkinter?

六眼飞鱼酱① 提交于 2019-12-06 04:46:24
Consider the following example: import asyncio import tkinter as tk class App(tk.Tk): def __init__(self): super().__init__() self.create_widgets() self._configure_bindings() # I believe it is not possible # to do this if the method needs # to be async as well def create_widgets(self): pass def _configure_bindings(self): self.bind('<F5>', self.spam) # what's the proper way? # does this method need to be async as well? async def spam(self, event): await self.do_something() async def do_something(): pass async def run_tk(root): try: while True: root.update() await asyncio.sleep(.01) except tk

Optimizing multiprocessing.Pool with expensive initialization

泄露秘密 提交于 2019-12-06 04:26:51
问题 Here is a complete simple working example import multiprocessing as mp import time import random class Foo: def __init__(self): # some expensive set up function in the real code self.x = 2 print('initializing') def run(self, y): time.sleep(random.random() / 10.) return self.x + y def f(y): foo = Foo() return foo.run(y) def main(): pool = mp.Pool(4) for result in pool.map(f, range(10)): print(result) pool.close() pool.join() if __name__ == '__main__': main() How can I modify it so Foo is only

SSL and Tkinter not present on source build of Python 3.5.2, Debian Linux

余生长醉 提交于 2019-12-06 04:26:16
I just now downloaded Python 3.5.2 onto my Debian machine and built it with: ./configure make make test sudo make install Everything worked, but in the make test output, it showed the installer as having skipped certain tests due to the modules _tkinter and _ssl not being installed. Furthermore, the lack of SSL makes me unable to use pip. This also happened on my build of 3.5.1, but I assumed that it was just an early, buggy version. How can I fix this? I especially need SSL in order to send emails. PADYMKO Since Python (properly name is CPython, because exists also Cython, Jython, PyPy and so

cx_Freeze Exe Application closes as soon as opens

懵懂的女人 提交于 2019-12-06 04:16:38
问题 I am trying to just convert my pygame python project to a .exe file using cx_Freeze. The setup file executes correctly and without error, but the issue is that when I run my .exe file the console window will open and close and my game window will not appear. The setup.py I am using: import os os.environ['TCL_LIBRARY'] = "C:\\Users\\MY_USERNAME\\AppData\\Local\\Programs\\Python\\Python35-32\\tcl\\tcl8.6" os.environ['TK_LIBRARY'] = "C:\\Users\\MY_USERNAME\\AppData\\Local\\Programs\\Python\