python-2.7

yaml file not getting copied when installing from setup.py

感情迁移 提交于 2021-01-29 09:30:11
问题 for my distutils package the yaml file along with python files is not getting copied setup.py from distutils.core import setup files = ["*.yaml", "package/*"] setup(name = "mypackage", version = "0.1", description = "description", author = "Ciasto", author_email = "me@email.com", packages = ['package'], package_data = {'package' : files }, scripts = ["scripts/runner"], ) this is the project directory structure: $ tree package/ |____ | |______init__.py | |____command.py | |____constants.py | |

Kivy: Sizing Buttons to fit wrapped text within dropdown

和自甴很熟 提交于 2021-01-29 08:53:42
问题 I'm having issues building a Kivy dropdown with word wrapping enabled for the text, such that the button widgets size accordingly to accommodate the full text. I have followed guidance from the stack overflow thread below and similar blog post that is also linked. Wrapping the text of a Kivy Label https://blog.kivy.org/2014/07/wrapping-text-in-kivys-label/ The text wraps as expected, however as the text string gets longer, there is an increasing amount of "padding" above and below the text

How to print values from lists in tabular format (python)?

谁都会走 提交于 2021-01-29 08:30:25
问题 Using python 2.7, I want to display the values in tabular format, without using pandas/prettytable. I am a beginner to python and am trying to learn. Below is the values I have in list listA = ["Alpha","Beta","gama","cat"] data = [["A","B","C","D"],["E","F","G","H"],["I","J","K","L"],["M","N","O","P"]] Expected output - to be displayed like below in tabular format : Alpha Beta gama cat A B C D E F G H I J K L M N O P I tried the following code, I am not getting the desired result: def print

Django Admin Issue - 'NoneType' object has no attribute 'user'

天涯浪子 提交于 2021-01-29 08:25:13
问题 Writing a blog engine with Django 1.5 and using the Django Admin. Everything was fine, until I added a ManyToManyField to a model, and added that field to the ModelAdmin's fieldsets, then I started to get this mysterious error when trying to load the admin page: 'NoneType' object has no attribute 'user' (Full stack trace further on below.) Why would the response object suddenly be None? If I remove the field from the fieldset, everything's fine again. My models look something a bit like this

two for loops in list comprehension python

让人想犯罪 __ 提交于 2021-01-29 08:16:18
问题 I have a list: f_array=['1000,1','100,10','100,-10'] I am trying to sum up all the first element in each value of the above array. I tried something like: number = sum([ num for num in item.split(",")[1] for item in f_array]) but it dint work. What would be the best way to do it ? 回答1: If you want to use nested loops then need to swap the order of the for loops: number = sum([num for item in f_array for num in item.split(",")[1]]) List comprehension loops are listed in nesting order , left to

how to use cosssim in gensim

大兔子大兔子 提交于 2021-01-29 08:07:15
问题 My questioon is about cossim usage. I have this fragment of a very big fuction: for elem in lList: temp = [] try: x = dict(np.ndenumerate(np.asarray(model[elem]))) except: if x not in embedDict.keys(): x = np.random.uniform(low=0.0, high=1.0, size=300) embedDict[elem] = x else: x = dict(np.ndenumerate(np.asarray(embedDict[elem]))) for w in ListWords: try: y = dict(np.ndenumerate(np.asarray(model[w]))) except: if y not in embedDict.keys(): y = np.random.uniform(low=0.0, high=1.0, size=300)

Python Recognizing An IP In A String

偶尔善良 提交于 2021-01-29 07:30:52
问题 I'm having a lot of trouble with this segment of code: command = "!ip" string = "!ip 127.0.0.1" if command in string: That's where I get stuck. After the first if statement I need another one to recognize any IP address just not 127.0.0.1. What's the easiest way of doing this? 回答1: I would give it a shot using regular expressions, where the regular expression (?:[0-9]{1,3}\.){3}[0-9]{1,3} is a simple match for an IP address. ip = '127.0.0.1' match = re.search(r'(?:[0-9]{1,3}\.){3}[0-9]{1,3}',

Netowrkx len() command giving a 'str' object error

泄露秘密 提交于 2021-01-29 07:10:34
问题 To start, I created a Network using 2014 flight data as explained here:https://ipython-books.github.io/142-drawing-flight-routes-with-networkx/ I'm trying to create smaller graphs using airline specific flight paths to test connectivity within each business, starting with American Airlines, I did the following: AASys = routes[ routes['source'].isin(airports_us.index) & routes['dest'].isin(airports_us.index) & routes['airline'].str.contains('AA')] AASys AAedges = AASys[['source', 'dest']]

How to double a char in a string?

巧了我就是萌 提交于 2021-01-29 06:56:12
问题 I am trying to write a function that takes two arguments, a string and a letter. The function should then double the number of letter in the string. For example: double_letters("Happy", "p") Happppy what i have done so far; def double_letter(strng, letter): new_word = "" for char in strng: if char == letter: pos = strng.index(char) new_word = letter+strng[pos:] But this is giving me the output: pppy how can i change the function to get the output: Happppy? 回答1: Use string.replace string =

Python webbrowser - Open a url without https://

蓝咒 提交于 2021-01-29 06:14:31
问题 I am trying to get python to open a website URL. This code works. import webbrowser url = 'http://www.example.com/' webbrowser.open(url) I have noticed that python will only open the URL is it has https:// at the beginning. Is it possible to get python to open the URL if it's in any of the formats in the examples below? url = 'http://www.example.com/' url = 'https://example.com/' url = 'www.example.com/' url = 'example.com/' The URLs will be pulled from outside sources so I can't change what