python-2.x

python input() EOF error and return value of type int?

岁酱吖の 提交于 2021-01-28 04:08:34
问题 I have 2 questions on these 2 short codes. 1. name = input('what: ') print(name) output what: 641u Traceback (most recent call last): File "/Users/vuthynun/PycharmProjects/untitled1/h/__init__.py", line 1, in <module> name = input('what: ') File "<string>", line 1 641u ^ SyntaxError: unexpected EOF while parsing Process finished with exit code 1 Why does it give me this error? 2. name = input('what: ') print(type(name)) output: what: 23 <type 'int'> Process finished with exit code 0 Why is

Specific range within a list (python)

孤人 提交于 2021-01-28 02:00:23
问题 I have a list of integers which I have extracted from a string of text, so when I print the list (which I have called test ) I get: ['135', '2256', '1984', '3985', '1991', '1023', '1999'] and I want to print or make a new list containing only numbers within a certain range, e.g. between 1000-2000. I tried the following, but it still returns all of the items in my original list. for i in test: if i>1000: print i elif i<2000: print i And I can't work out why it would still be printing numbers

Cannot reshape array of size into shape

本小妞迷上赌 提交于 2021-01-04 09:09:28
问题 I am following a machine learning video on youtube at https://www.youtube.com/watch?v=lbFEZAXzk0g. The tutorial is in python2 so I need to convert it into python3. Here is the section of the code I am having an error with: def load_mnist_images(filename): if not os.path.exists(filename): download(filename) with gzip.open(filename,'rb') as file: data = numpy.frombuffer(file.read(),numpy.uint8, offset=16) data = data.reshape(-1,1,28,28) return data/numpy.float32(256) I am getting this error:

Why is it impossible to mix Python2 with Python3?

╄→гoц情女王★ 提交于 2020-12-11 10:17:09
问题 Despite all that has been said and written on Python2 vs Python3, I have been unable to identify why the developers made it impossible to mix Python2 and Python3 code. Surely there must be a reason for this? In Fortran, for instance, the many versions are incompatible with each other, but they can still happily co-exist within the same project. The same applies to C and C++: some C code is not compatible with C++, but the compiler is able to recognize the correct language using the file