Iam new to Python Need Help - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Iam new to Python Need Help (/thread-10547.html) |
Iam new to Python Need Help - hitesh222002 - May-24-2018 Hello All, I tried running the below program in the 'Python 2.7.14 Shell', but I did not get any output at the end of the program. f = open("C:/test/my_data.txt") h = f.readline() lines = f.readlines() # select dno,sex,sum(sal) from emp group by dno,sex; res = {} dno = w[-1].split("\n")[0] sex = w[-2] mykey = (dno,sex) sal = int(w[2]) if res.get(mykey) == None: res[mykey] = sal else: res[mykey] += sal print("aggregations",res) // my_data contains the following data : id, name, sal, sex,deptno 101, Amar, 2000, M 11 102, Sai, 3000, F 11 103, Pran, 5000, M 12 Please help me RE: Iam new to Python Need Help - nilamo - May-24-2018 (May-24-2018, 03:33 PM)hitesh222002 Wrote: f = open("C:/test/my_data.txt") (May-24-2018, 03:33 PM)hitesh222002 Wrote: // my_data contains the following data : Your data is in a file named my_data , but the program is reading my_data.txt . Those are not the same thing. There's no output, because there's no input.
RE: Iam new to Python Need Help - buran - May-25-2018 well even if the indentation is correct, this code would raise an exception because w is not defined. So you get a Traceback. Do as Larz60+ advised you - put your code in python tags with correct indentation. Post also Full traceback you get in error tags |