|
When you say 'everything' what did you try? |
Did you try updating the drivers? |
You are not closing the file, but trying to "close" the filename, which is a string. What you need to do is to save the return value of the open(...) in a variable, and call close on it: infile = open(file1) indata = infile.read() infile.close() Instead of calling close explicitly, in modern code it is preferable to use the with statement; when the with statement is exited, either because the code run to completion, or because an exception was thrown, the file is closed automatically: from sys import argv from os.path import exists kay, So I am needing to retrieve the rows in a database table that where inserted the previous month of the current. shop_orders is the database. I do have a datetime in each row for the order date or o_date and that will be used to determine when it was entered. I came up with this function in codeigniter model. The first portion in the code determines what the first day of last month is and puts into the same format that is stored in the database. The second portion retrieves the information from the database. I'm just not sure what to place in the where line to retrieve the results only from the first day of last month to the last day of last month. The first portion of the below code outputs just like this: Today is: 2014/05/30 the first day of last month was: 2014/04/01 and the last day of last month was: 2014/04/30. I need to tell the second block: Select * from shop_orders where o_date is between 2014/04/01 and 2014/04/30 Obviously that isn't correct sql, what is? My real question. function get_last_month_order_count() { $date = date('Y/m/d'); $today = new DateTime( $date ); $today->modify( 'first day of last month' ); $firstDay = $today->format( 'Y/m/d' ); $today = new DateTime( $date ); $today->modify( 'last day of last month' ); $lastDay = $today->format( 'Y/m/d' ); $this->db->select('*'); $this->db->from('shop_orders'); $this->db->where('o_date', ''); return $this->db->count_all_results(); } script, input_file_name, output_file_name = argv print("Copying from {} to {}:".format(input_file_name, output_file_name)) with open(input_file_name) as input_file: data = input_file.read() print("The input file is {} bytes long".format(len(data))) print("Does the output file exist? {}".format(exists(output_file_name))) with open(output_file_name, 'w') as output_file: output_file.write(data) Did you make sure the volume is full from the speaker icon in the taskbar? |
Did you make sure no sounds are muted when you click on mixer? |
The code was taken from "Learn Python The Hard Way" exercise 17 but I've tweaked with it a bit, so hence I'm asking the question: from sys import argv from os.path import exists script, file1, file2 = argv print "Copying from %s to %s:" % (file1, file2) indata = open(file1).read() print "The input file is %d bytes long" % len(indata) print "Does the output file exist? %r" % exists(file2) outdata = open(file2, 'w').write(indata) When i add the lines: file1.close() file2.close() at the end of this code. I get the output on terminal: Copying from python/test.txt to python/sampleout.txt: The input file is 18 bytes long Does the output file exist? True Traceback (most recent call last): File "python/myprogram0.py", line 16, in |
No comments:
Post a Comment