[Solved] Python – ValueError: invalid literal for int() with base 10: ‘hello’

The following solution worked. Instead of using int(x) , we need to use len(x.encode(‘utf-8′)) so the final code is updated as import io with io.open(r’C:\Python\Data\somefile.txt’,’r+’) as fp: bytecolumn = (line.rsplit(None,1)[1] for line in fp) bytes = ( len(x.encode(‘utf-8’)) for x in bytecolumn if x != ‘-‘) print(‘Total’, sum(bytes)) solved Python – ValueError: invalid literal for … Read more

[Solved] Basic Python 2.7 Math Script (4 variables and 3 consecutive math operations) [closed]

If I understand the problem correctly, I would ask a user what operation he wants to go with: math_option =raw_input(‘Choose the math operation: ‘) and later on check what option was chosen: if math_option == “add”: print add(x, y) if math_option == “multiply”: add_num = add(x,y) mul_num = multiply(math_option,z) print mul_num and so on 1 … Read more

[Solved] Python returns “SyntaxError: invalid syntax sys module” [closed]

import pandas as pd sys.path.insert(0, “/usr/lib/python2.7/site-packages”) This line contains two statements. Split them into two lines: import pandas as pd sys.path.insert(0, “/usr/lib/python2.7/site-packages”) Or, if they must be in one line, separate them with semicolon (highly not recomended!!!): import pandas as pd; sys.path.insert(0, “/usr/lib/python2.7/site-packages”) 1 solved Python returns “SyntaxError: invalid syntax sys module” [closed]

[Solved] What are the Similarities between Dictionary and Array data types? [closed]

A dictionary maps strings to values. An array maps integers to values. That is about it! So, seriously: in the end, both data structures map a “key set” to values. For dictionaries, the keys can of (almost) arbitrary type, without any constraint on them (besides being “hash able”). Whereas an array maps a consecutive range … Read more

[Solved] How to avoid ‘1’ when incoming is none

Can you try the following: req_keys = [‘col1’, ‘col2’, ‘col3’, ‘col4’] all_list = [incoming[i] for i in req_keys] all_list = [i for i in all_list if i] print(‘1’.join(all_list)) Example: incoming = {} incoming[‘col1’] = ‘a’ incoming[‘col2’] = None incoming[‘col3’] = ‘c’ incoming[‘col4’] = None Output: a1c Another Example: incoming = {} incoming[‘col1’] = ‘a’ incoming[‘col2’] … Read more

[Solved] Return Max and min not working right [closed]

Assuming that you want to get the values after the comma, you can do something like this: with open(‘ops.log’, ‘r’) as log_fh: data = [int(line.split(‘,’)[1]) for line in log_fh.readlines()] print max(data), min(data) solved Return Max and min not working right [closed]

[Solved] Need Help converting to python 2.7

You might want to try future statements. Basically, keep the code the way it is, and backport features to 2.7. I already see the print statements causing problems, so at the top just add from __future__ import print_statement. This will cause Python 2.7 to read print as if it were running in 3.x. Running the … Read more

[Solved] Pyconfigini: ImportError: No module named lib.pyconfigini

The problem is that you’re running python setting.py from app/ directory (which at the moment of script start becomes current working directory) . Python looks for modules in directories that are listed in PYTHONPATH environment variable (you can get access to it from Python code via sys.path variable). This list of directories contains standard site-packages, … Read more