python-3.x

why * used before declaring a variable in python [duplicate]

邮差的信 提交于 2021-02-16 14:05:12
问题 This question already has answers here : Star * operator on left vs right side of an assignment statement (1 answer) Please explain the *elements,=iterable construct [duplicate] (1 answer) Closed 3 years ago . I just started to learn python. I was following an example where they have used * before declaring a variable. My question is that what is the purpose of using this. Example, I am following for i in range(n): name, *l = input().split() s = list(map(float, l)) a[name] = s After printing

“TypeError: 'type' object is not subscriptable” in a function signature

陌路散爱 提交于 2021-02-16 14:00:48
问题 Why am I receiving this error when I run this code? Traceback (most recent call last): File "main.py", line 13, in <module> def twoSum(self, nums: list[int], target: int) -> list[int]: TypeError: 'type' object is not subscriptable nums = [4,5,6,7,8,9] target = 13 def twoSum(self, nums: list[int], target: int) -> list[int]: dictionary = {} answer = [] for i in range(len(nums)): secondNumber = target-nums[i] if(secondNumber in dictionary.keys()): secondIndex = nums.index(secondNumber) if(i !=

How to set a timeout for Input

╄→尐↘猪︶ㄣ 提交于 2021-02-16 12:59:39
问题 If you wait out the 4 seconds it says "You ran out of time" which is good. But then, to keep the loop going, you will have to press the enter key to continue. I want so that when it prints "You ran out of time" underneath instead of just typing, that it displays an input statement like "Type 'attack' to keep going" and the loop would continue from where it was. from threading import Timer import time monsterhp = int(800) y = 150 while monsterhp > 0: timeout = 4 t = Timer(timeout, print, ['You

How to set a timeout for Input

送分小仙女□ 提交于 2021-02-16 12:56:58
问题 If you wait out the 4 seconds it says "You ran out of time" which is good. But then, to keep the loop going, you will have to press the enter key to continue. I want so that when it prints "You ran out of time" underneath instead of just typing, that it displays an input statement like "Type 'attack' to keep going" and the loop would continue from where it was. from threading import Timer import time monsterhp = int(800) y = 150 while monsterhp > 0: timeout = 4 t = Timer(timeout, print, ['You

Python Selenium: Block-Title is not properly verified. (Magento Cloud)

折月煮酒 提交于 2021-02-16 11:27:52
问题 Details: Currently I am writing within a project based on Magento Cloud test cases with Python-Selenium. So far everything is fine. Currently I only have one problem, which I can't explain anymore. Actually it's only about the verification of a text. Or the verification of a block title within a profile page. I would like to secure multiple times, and thus define 2 different test cases. issues I always get the following message. selenium.common.exceptions.StaleElementReferenceException:

Python: Remove duplicates for a specific item from list

丶灬走出姿态 提交于 2021-02-16 10:52:40
问题 I have a list of item, where I want to remove the occurrence of any duplicates for one item, but keep any duplicates for the rest. I.e. I start with the following list mylist = [4, 1, 2, 6, 1, 0, 9, 8, 0, 9] I want to remove any duplicates of 0 but keep the duplicates of 1 and 9 . My current solution is the following: mylist = [i for i in mylist if i != 0] mylist.add(0) Is there a nice way of keeping one occurrence of 0 besides the following? for i in mylist: if mylist.count(0) > 1: mylist

How to reliably check if a domain has been registered or is available?

人走茶凉 提交于 2021-02-16 10:00:33
问题 Objective I need a reliable way to check in Python if a domain of any TLD has been registered or is available. The bold phrases are the key points that I'm struggling with. What I tried? WHOIS is the obvious way to do the check and an existing Python library like the popular python-whois was my first try. The problem is that it doesn't seem to be able to retrieve information for some of the TLDs, e.g. .run , while it works mostly fine for older ones, e.g. .com . So if python-whois is not

In Tkinter, How I disable Entry?

我的未来我决定 提交于 2021-02-16 06:05:59
问题 How I disable Entry in Tkinter. def com(): .... entryy=Entry() entryy.pack() button=Button(text="Enter!", command=com, font=(24)) button.pack(expand="yes", anchor="center") As I said How I disable Entry in com function? 回答1: Set state to 'disabled' . For example: from tkinter import * root = Tk() entry = Entry(root, state='disabled') entry.pack() root.mainloop() or from tkinter import * root = Tk() entry = Entry(root) entry.config(state='disabled') # OR entry['state'] = 'disabled' entry.pack(

ImportError: MagickWand shared library not found[windows]

只谈情不闲聊 提交于 2021-02-16 05:36:41
问题 Good morning, After a lot of attemps running from wand.image import Image I get the following error: Traceback (most recent call last): File "C:\Users\XXXXX\PycharmProjects\PDF_convert\venv\lib\site-packages\wand\api.py", line 180, in <module> libraries = load_library() File "C:\Users\XXXXX\PycharmProjects\PDF_convert\venv\lib\site-packages\wand\api.py", line 135, in load_library raise IOError('cannot find library; tried paths: ' + repr(tried_paths)) OSError: cannot find library; tried paths:

ImportError: MagickWand shared library not found[windows]

房东的猫 提交于 2021-02-16 05:33:47
问题 Good morning, After a lot of attemps running from wand.image import Image I get the following error: Traceback (most recent call last): File "C:\Users\XXXXX\PycharmProjects\PDF_convert\venv\lib\site-packages\wand\api.py", line 180, in <module> libraries = load_library() File "C:\Users\XXXXX\PycharmProjects\PDF_convert\venv\lib\site-packages\wand\api.py", line 135, in load_library raise IOError('cannot find library; tried paths: ' + repr(tried_paths)) OSError: cannot find library; tried paths: