python-3.6

Creating new columns based on value from another column in pandas

醉酒当歌 提交于 2020-01-23 01:39:05
问题 I have this pandas dataframe with column "Code" that contains the sequential hierarchical code. My goal is to create new columns with each hierarchical level code and its name as followed: Original data: Code Name 0 A USA 1 AM Massachusetts 2 AMB Boston 3 AMS Springfield 4 D Germany 5 DB Brandenburg 6 DBB Berlin 7 DBD Dresden My Goal: Code Name Level1 Level1Name Level2 Level2Name Level3 Level3Name 0 A USA A USA AM Massachusetts AMB Boston 1 AM Massachusetts A USA AM Massachusetts AMB Boston 2

Find all occurrences of a character in a String

空扰寡人 提交于 2020-01-21 09:14:48
问题 I'm really new to python and trying to build a Hangman Game for practice. I'm using Python 3.6.1 The User can enter a letter and I want to tell him if there is any occurrence of that letter in the word and where it is. I get the total number of occurrences by using occurrences = currentWord.count(guess) I have firstLetterIndex = (currentWord.find(guess)) , to get the index. Now I have the index of the first Letter, but what if the word has this letter multiple times? I tried secondLetterIndex

Find all occurrences of a character in a String

梦想的初衷 提交于 2020-01-21 09:14:00
问题 I'm really new to python and trying to build a Hangman Game for practice. I'm using Python 3.6.1 The User can enter a letter and I want to tell him if there is any occurrence of that letter in the word and where it is. I get the total number of occurrences by using occurrences = currentWord.count(guess) I have firstLetterIndex = (currentWord.find(guess)) , to get the index. Now I have the index of the first Letter, but what if the word has this letter multiple times? I tried secondLetterIndex

How to capture screenshot on test case failure for Python Unittest

廉价感情. 提交于 2020-01-14 20:08:51
问题 I am using Python 3.6.5 with the following libraries: Appium-Python-Client==0.26 unittest2==1.1.0 selenium==3.5.0 pytest==3.6.3 Now I need to capture the screenshot in case of test failure, So intentionally I did put a false statement self.driver.find_element_by_css_selector('test') . I am using sys.exc_info() . But when I executing below code using a command: py.test untitled.py or python3 -m unittest untitled.py it does not capturing it. Code: import sys, time, unittest2 from selenium

How to capture screenshot on test case failure for Python Unittest

邮差的信 提交于 2020-01-14 20:08:13
问题 I am using Python 3.6.5 with the following libraries: Appium-Python-Client==0.26 unittest2==1.1.0 selenium==3.5.0 pytest==3.6.3 Now I need to capture the screenshot in case of test failure, So intentionally I did put a false statement self.driver.find_element_by_css_selector('test') . I am using sys.exc_info() . But when I executing below code using a command: py.test untitled.py or python3 -m unittest untitled.py it does not capturing it. Code: import sys, time, unittest2 from selenium

Python SVG converter creates empty file

早过忘川 提交于 2020-01-14 08:44:08
问题 I have some code below that is supposed to convert a SVG image to a PNG. It runs without errors but creates a PNG file that is blank instead of one with the same image as the original SVG. I did find that it is not an error with cairo but more one relating to rsvg, which I got here. import cairo import rsvg img = cairo.ImageSurface(cairo.FORMAT_ARGB32, 640,480) ctx = cairo.Context(img) handle= rsvghandler.Handle('example.svg') handle.render_cairo(ctx) img.write_to_png("svg.png") I am using

What is the correct way to type hint a homogenous Queue in Python3.6 (especially for PyCharm)?

大憨熊 提交于 2020-01-14 08:27:38
问题 I'm writing a fractal generator in Python 3.6, and I use multiprocessing.Queue s to pass messages from the main thread to the workers. This is what I've tried so far, but PyCharm doesn't seem to be able to infer attribute types for items taken from the queues: from typing import NamedTuple, Any, Generic, TypeVar, Tuple from multiprocessing import Process, Queue T = TypeVar() class Message(NamedTuple): method: str id: str data: Any = None class TypedQueue(Generic[T]): def get(self) -> T: ...

Is the example of the descriptor protocol in the Python 3.6 documentation incorrect?

独自空忆成欢 提交于 2020-01-14 06:47:39
问题 I am new to Python and looking through its documentation I encountered the following example of the descriptor protocol that in my opinion is incorrect. . It looks like class IntField: def __get__(self, instance, owner): return instance.__dict__[self.name] def __set__(self, instance, value): if not isinstance(value, int): raise ValueError(f'expecting integer in {self.name}') instance.__dict__[self.name] = value # this is the new initializer: def __set_name__(self, owner, name): self.name =

Cloning a celery chain

送分小仙女□ 提交于 2020-01-14 04:46:12
问题 I have an interesting issue attempting to clone a celery chain for use in a group, my intended use case is something like group([chain.clone(args=args) for args in it]) however it keeps complaining about not having enough arguments. I have broken this down using the below in a file named tasks.py @app.task def add(x,y): return x+y and then from the python shell >>> from tasks import add >>> chain=add.s()|add.s(1) >>> chain magic_carpet.celery.add() | add(1) >>> chain.args () >>> chain.delay(2

AWS SQS trigger Step Functions

自作多情 提交于 2020-01-13 10:13:50
问题 Quick question: Is it possible to trigger the execution of a Step Function after an SQS message was sent?, if so, how would you specify it into the cloudformation yaml file? Thanks in advance. 回答1: The first think to consider is this: do you really need to use SQS to start a Step Functions state machine? Can you use API gateway instead? Or could you write your messages to a S3 bucket and use the CloudWatch events to start a state machine? If you must use SQS, then you will need to have a