python-2.7

A more compact __repr__ for my numpy array?

狂风中的少年 提交于 2021-02-10 06:39:45
问题 When I show an array, the default __repr__() method for ndarray objects is too big for what I would like to do: a = np.eye(32) b = {'hello':42, 'array':a} b produces: {'array': array([[ 1., 0., 0., ..., 0., 0., 0.], [ 0., 1., 0., ..., 0., 0., 0.], [ 0., 0., 1., ..., 0., 0., 0.], ..., [ 0., 0., 0., ..., 1., 0., 0.], [ 0., 0., 0., ..., 0., 1., 0.], [ 0., 0., 0., ..., 0., 0., 1.]]), 'hello': 42} I tried an ugly solution, reassigning __repr__ : def wow(): return "wow!" a.__repr__ = wow which

pip install enum not working showing the error of 'intflag' doesnt have

孤人 提交于 2021-02-10 06:27:07
问题 pip install Enum is not working is showing the error of AttributeError:module 'enum' has no attribute 'IntFlag' 回答1: enum34 is the stdlib Enum backport, but it only supports features found up to 3.5. If you want features found in 3.6 you'll need to use aenum 1 . 1 Disclosure: I am the author of the Python stdlib Enum, the enum34 backport, and the Advanced Enumeration (aenum) library. 来源: https://stackoverflow.com/questions/44745374/pip-install-enum-not-working-showing-the-error-of-intflag

pip install enum not working showing the error of 'intflag' doesnt have

人盡茶涼 提交于 2021-02-10 06:26:09
问题 pip install Enum is not working is showing the error of AttributeError:module 'enum' has no attribute 'IntFlag' 回答1: enum34 is the stdlib Enum backport, but it only supports features found up to 3.5. If you want features found in 3.6 you'll need to use aenum 1 . 1 Disclosure: I am the author of the Python stdlib Enum, the enum34 backport, and the Advanced Enumeration (aenum) library. 来源: https://stackoverflow.com/questions/44745374/pip-install-enum-not-working-showing-the-error-of-intflag

Python split a string containing a list

半腔热情 提交于 2021-02-10 06:25:34
问题 I would like to split a line from a file, but got stuck. Let's say i have this line in my file: John, Smith, 1580, ["cool","line","splitting"] Now I tried to make this: line = line.split(',') print line Of course it returns: ['John', ' Smith', ' 1580', ' ["cool"', '"line"', '"splitting"]'] The problem is the list from file. I can't read it properly. I want it to look something like: ['John', 'Smith', 1580, ["cool", "line", "splitting"]] Can someone help me do it this way? 回答1: You can use ast

Google Endpoints GET request URL parameters [Python]

跟風遠走 提交于 2021-02-10 06:17:50
问题 I am currently working on a small project where I need to write a GET handler. I am working from the Echo example provided in the endpoints documentation. I have my resource container: GET_EMAIL_RESOURCE = endpoints.ResourceContainer( message_types.VoidMessage, i = messages.IntegerField(1, default = 1) ) And I have my handler: @endpoints.method( GET_EMAIL_RESOURCE, EchoResponse, path='echo/getEmails/{i}', http_method='GET', name='echo_get_emails' ) def echo_get_emails(self, request): if

Google Endpoints GET request URL parameters [Python]

馋奶兔 提交于 2021-02-10 06:17:07
问题 I am currently working on a small project where I need to write a GET handler. I am working from the Echo example provided in the endpoints documentation. I have my resource container: GET_EMAIL_RESOURCE = endpoints.ResourceContainer( message_types.VoidMessage, i = messages.IntegerField(1, default = 1) ) And I have my handler: @endpoints.method( GET_EMAIL_RESOURCE, EchoResponse, path='echo/getEmails/{i}', http_method='GET', name='echo_get_emails' ) def echo_get_emails(self, request): if

Remove period[.] and comma[,] from string if these does not occur between numbers

↘锁芯ラ 提交于 2021-02-10 06:16:06
问题 I want to remove comma and period from a text only when these does not occur between numbers. So, following text should return "This shirt, is very nice. It costs DKK ,.1.500,00,." "This shirt is very nice It costs DKK 1.500,00" I tried with text = re.sub("(?<=[a-z])([[$],.]+)", " ", text) but it does not substitute anything in the text. 回答1: You could try this: >>> s = "This shirt, is very nice. It costs DKK ,.1.500,00,." >>> re.sub('(?<=\D)[.,]|[.,](?=\D)', '', s) 'This shirt is very nice

How to get help on methods in Python? [duplicate]

柔情痞子 提交于 2021-02-10 06:10:06
问题 This question already has answers here : python: how to get information about a function? (4 answers) Closed 6 years ago . whenever I use help() on a method I get a weird looking output. For example, help(obj.readline) gives me the following output: Help on built-in function readline: readline(...) That's all i get. I don't know how to interpret it.Why there is no description about the method? Can somebody please explain to me what's going on? 回答1: Is this weird output? >>> f = open('data.txt

Python- scipy ODR going crazy

。_饼干妹妹 提交于 2021-02-10 06:09:37
问题 I would like to use scipy's ODR to fit a curve to a set of variables with variances. In this case, I am fitting a linear function with a set Y axis crossing point (e.g. a*x+100 ). Due to my inability to find an estimator (I asked about that here), I am using scipy.optimize curve_fit to estimate the initial a value. Now, the function works perfectly without standard deviation, but when I add it, the output makes completely no sense (the curve is far above all of the points). What could be the

python-re.sub() and unicode

孤者浪人 提交于 2021-02-10 06:06:35
问题 I want to replace all emoji with '' but my regEx doesn't work. For example, content= u'?\u86cb\u767d12\U0001f633\uff0c\u4f53\u6e29\u65e9\u6668\u6b63\u5e38\uff0c\u5348\u540e\u665a\u95f4\u53d1\u70ed\uff0c\u6211\u73b0\u5728\u8be5\u548b\U0001f633?' and I want to replace all the forms like \U0001f633 with '' so I write the code: print re.sub(ur'\\U[0-9a-fA-F]{8}','',content) But it doesn't work. Thanks a lot. 回答1: You won't be able to recognize properly decoded unicode codepoints that way (as