I am trying to output a list to a csv file and the line below work fine.
I need help with changing the delimiter from the default comma(,) to tab delimited.
csv_file = open('output.csv', 'w')
csv_writer = csv.writer(csv_file)
Help very much appreciated
Kaf
8 6206
This is done by setting a dialect in your csv writer. Dialect is an csv object and you can set the dialect.delimiter to '/t'.
See here
Thanks for the pointer Glenton. I got it to work by doing this
csv_writer = csv.writer(csv_file, delimiter="\t")
I am trying to use a date in an SQL where clause
prevday = datetime.date.today()-datetime.timedelta(1)
prev_day = prevday.strftime("%d-%b-%y")
and this is the SQL statement but it does not work
cur.execute("""select switch,percent_occupied from Table_name where switch =
('4DYHTE') and trunc(date_time) = %s""",("prev_day",))
I will appreciate any help
Thanks
Kaf
Can you let us know what you mean by "does not work"? What's the error message? Does the prev_day need quotation marks?
Well i am trying to pass the data in the variable prev_day which is in this format dd-mon-yy to the SQL query.
without the quotes i get an invalid variable error
prevday = datetime.date.today()-datetime.timedelta(1)
Print prevday to see what it contains. I don't think there is a default for timedelta so you have to specify one whatever, days=1, weeks=1, etc. From the docs
class datetime.timedelta([days[, seconds[, microseconds[, milliseconds[, minutes[, hours[, weeks]]]]]]])
Hello Glenton,
Sorry about this but i made a mistake about the error i was getting.
When i run it with or without the quotes this is the error message i get
Traceback (most recent call last):
File "spit.py", line 9, in <module>
('4DYHTE') and trunc(date_time) = %s""",("prev_day",))
cx_Oracle.DatabaseError: ORA-01036: illegal variable name/number
dwblas,
Concerning what is stored in prevday its the date for the previous day
>>> import datetime
>>> prevday = datetime.date.today()-datetime.timedelta(1)
>>> print prevday
2012-01-04
>>>
and i format it with this prev_day = prevday.strftime("%d-%b-%y")
to get
>>> prev_day = prevday.strftime("%d-%b-%y")
>>> print prev_day
04-Jan-12
>>>
which i want to pass to the SQL statement for the query.
Thanks for your help
i finally figured it out by doing this
cur.execute("""select switch,percent_occupied from Table_name where switch = '4DYHTE' and trunc(date_time) = ('%s')""" % (prev_day))
bvdet 2,851
Expert Mod 2GB
Congratulations on solving your problem. Thanks for the feedback!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: rhungund |
last post by:
Hey all...
I'm submitting various form variables as arrays, so when I do try to
access them when the form is submitted, i do a split on the variable
and pop it into an array.
for example:...
|
by: Piotr |
last post by:
Is it any way to change comma to point when it is typped into the INPUT
field?
|
by: silly |
last post by:
/*Thanks again to thos who helped with my
'more hand written integer pow() functions (LONG POST)' query.
I needed to write a function to write out integers and after looking at some
stuff
on...
|
by: Koray Bostancı |
last post by:
Hi all,
When i type python in terminal it runs the python2.3 interpreter, but i
want to use 2.4 and Python2.4 package is already installed.
How can i change the default python in my system? I...
|
by: ye juan |
last post by:
Hi, all
I have some questions to ask:
1. How can I add a standard module named "datetime" in
Jython when the error happens :"Traceback (innermost
last):
File "C:\python\test.py", line 3, in...
|
by: fatalserpent |
last post by:
Here is the basic code (yes, I know its tiny).
x =
print "x =", x
for m in x: print m
I want to modify this so it will output to a file called 1. What I want
is to have that file direct its...
|
by: kirbybowl |
last post by:
I have been using --#SET TERMINATOR to change the delimiter within my CLP scripts. In my situation, the CLP scripts are generated from a database of CLP commands (written by many authors), thus the...
|
by: spreadbetting |
last post by:
I'm trying to split a string into an separate arrays but the data is
only delimited by a comma. The actual data is one long string but the
info is in a regular format and repeats after every five...
|
by: sandro dentella |
last post by:
Hi,
I'm having a little problem while using python mode. I'm used to hit
C-c C-c and have a Python Output buffer opened with the output. Now,
on Ubuntu 7.10 and 8.04, C-c C-c sends to the...
|
by: Vidhyapc |
last post by:
Hi, My query gets directly executed in a report and a parameter is a varchar2 that gets the user_id passed with a comma delimiter but no quotes to the user_id( which are sometimes non-numeric), how...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |