python-3.5

Sample from a Bayesian network in pomegranate

为君一笑 提交于 2020-02-23 06:44:15
问题 I constructed a Bayesian network using from_samples() in pomegranate. I'm able to get maximally likely predictions from the model using model.predict() . I wanted to know if there is a way to sample from this Bayesian network conditionally(or unconditionally)? i.e. is there a get random samples from the network and not the maximally likely predictions? I looked at model.sample() , but it was raising NotImplementedError . Also if this is not possible to do using pomegranate , what other

Reduce execution time on huge list generation

无人久伴 提交于 2020-02-02 12:23:11
问题 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)])))

Can't import Pyperclip

亡梦爱人 提交于 2020-02-02 06:19:20
问题 I am having trouble importing Pyperclip in IDLE. I am running windows 7 (64-bit). I have Python 3.5.2 Installed on: C:\Python\Python35. I opened command prompt and initiated the install by typing pip install pyperclip after changing directory to C:\Python\Python35\Scripts. It successfully installed Pyperclip-1.5.27. I then went to IDLE and typed in import pyperclip but the following error is showing up: Traceback (most recent call last): File "", line 1, in import pyperclip ImportError: No

Using async/await keywords with Tk.after() method of tkinter

半城伤御伤魂 提交于 2020-01-24 21:44:08
问题 I am creating a cryptocurrency exchange API client using Python3.5 and Tkinter. I have several displays that I want to update asynchronously every 10 seconds. I am able to update the displays every 10 seconds using Tk.after() like in this example def updateLoans(): offers = dd.loanOffers() demands = dd.loanDemands() w.LoanOfferView.delete(1.0, END) w.LoanDemandView.delete(1.0, END) w.LoanOfferView.insert(END, offers) w.LoanDemandView.insert(END, demands) print('loans refreshed') root.after

Converting to Emoji

不想你离开。 提交于 2020-01-24 11:02:56
问题 so I am trying to take this data that uses unicode indicators and make it print with emojis. It is currently in a txt. file but I will write to an excel file later. So anyways I am getting an error I am not sure what to do with. This is the text I am reading: "Thanks @UglyGod \ud83d\ude4f https:\\/\\/t.co\\/8zVVNtv1o6\" "RT @Rosssen: Multiculti beatdown \ud83d\ude4f https:\\/\\/t.co\\/fhwVkjhFFC\" And here is my code: sampleFile= open('tweets.txt', 'r').read() splitFile=sampleFile.split('\n')

how to switch between two application using pywinauto 0.5.4

微笑、不失礼 提交于 2020-01-23 16:11:30
问题 I am trying to automate a task of copying every single line one by one from Notepad and pasting it the application and then clicking at a button and then copying the output to a third notepad file. I am using pywinauto 0.5.4 of python for this automation and I am not getting any help on how to switch between different application from pywinauto import application app = application.Application() app = application.Application() app.start("Notepad.exe") app.start("C:\Program Files (x86)\eSpeak

Making 1 milion requests with aiohttp/asyncio - literally

喜夏-厌秋 提交于 2020-01-22 15:11:06
问题 I followed up this tutorial: https://pawelmhm.github.io/asyncio/python/aiohttp/2016/04/22/asyncio-aiohttp.html and everything works fine when I am doing like 50 000 requests. But I need to do 1 milion API calls and then I have problem with this code: url = "http://some_url.com/?id={}" tasks = set() sem = asyncio.Semaphore(MAX_SIM_CONNS) for i in range(1, LAST_ID + 1): task = asyncio.ensure_future(bound_fetch(sem, url.format(i))) tasks.add(task) responses = asyncio.gather(*tasks) return await

How can I create a type hint that my returned list contains strings?

僤鯓⒐⒋嵵緔 提交于 2020-01-22 13:23:19
问题 I want to use Type Hints in my Python program. How can I create Type Hints for complex data structures like lists with strings a generator returning integers? Example def names() -> list: # I would like to specify that the list contains strings? return ['Amelie', 'John', 'Carmen'] def numbers(): # Which type should I specify for `numbers()`? for num in range(100): yield num 回答1: Use the typing module; it contains generics , type objects you can use to specify containers with constraints on

Can't remove margins from QVBoxLayout

拥有回忆 提交于 2020-01-21 16:41:26
问题 I have set up an image button with some text, but the image does not align with the text due to some extra margins. How can I get rid of these margins? I have tried setting setContentsMargins(0,0,0,0) and setSpacing(0) on various components but it doesn't seem to affect the correct margins. Here is a demo: from PyQt5.QtGui import * from PyQt5.QtWidgets import * from PyQt5.QtCore import * class ImageButton(QWidget): def __init__(self, img_location): QWidget.__init__(self) self.img_location =

Getting formula while reading cell data in OpenPyXL

岁酱吖の 提交于 2020-01-17 07:43:33
问题 I want to update value in excel and get new updated value of output cell in excel using OpenPyXL in python 3 Below is code import openpyxl xfile = openpyxl.load_workbook('sheet.xlsx') sheet = xfile.get_sheet_by_name('Sheet1') print (sheet['D2'].value) sheet['A2'] = 3 print (sheet['D2']) xfile.save('sheet.xlsx') and below is sample data in excel : Image of excel file and below is output I am getting python3 xl.py =SUM(A2:C2) <Cell 'Sheet1'.D2> How can I get value of this cell as calculated