Python | Expecting type INT, but if STR entered?

I'm asking the user for an integer type input. But if the user accidentally inputs string type, I want it to tell the use they incorrectly answer the question. Like this: question1 = int(input("Enter a number: ")) if question1 != int: print("Ple...
more »

2017-10-13 00:10 (2) Answers

How to configure JSON for graphql query?

I am trying to send queries to a Shopify site using the Storefront API provided. The API in question requires I use GraphQL, which is just JSON POSTed to a url endpoint. Given a query like this: query { shop{ products(first: 2) { edges {...
more »

2017-10-12 23:10 (1) Answers

utf16 vs utf-16

Which line from below is correct? I do know all these available encodings? with open(filename, 'w', encoding='utf16') as fp: with open(filename, 'w', encoding='utf-16') as fp: ...
more »

2017-10-11 23:10 (1) Answers

Override dict() on class

I'm trying to make a dict-like class in Python. When you make a class, you have certain methods that tell Python how to make a built-in class. For example, overriding the __int__ method tells Python what to return if the user uses int() on an instan...
more »

2017-10-08 04:10 (2) Answers

Python Dask Running Bag operations in parallel

I am trying to run a series of operations on a json file using Dask and read_text but I find that when I check Linux Systems Monitor, only one core is ever used at 100%. How do I know if the operations I am performing on a Dask Bag are able to be par...
more »

2017-10-08 01:10 (1) Answers

Find longest unique substring in string python

I am trying that age old question (there are multitudes of versions around) of finding the longest substring of a string which doesn't contain repeated characters. I can't work out why my attempt doesn't work properly: def findLongest(inputStr): ...
more »

2017-10-06 22:10 (2) Answers

foreign key only show owner field django

I have two Model classes In django restful API: class Titles(models.Model): title_links=models.CharField(max_length=500) created_by=models.ForeignKey(User,null=True) def __str__(self): return '{}'.format(self.title_links) class...
more »

2017-10-02 16:10 (1) Answers