Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Cannot get past this string related issue

Reply
Thread Tools

Cannot get past this string related issue

 
 
Oltmans
Guest
Posts: n/a
 
      04-26-2011
Greetings, I hope you're doing well. I'm stuck in a strange issue,
most likely due to my own ignorance. I'm reading a config file using
ConfigParser module and passing database related info to _mssql.
Following doesn't work


config = ConfigParser.ConfigParser()
config.read('configs.txt')
server_info = config.get("DB_INFO","server")
db = config.get("DB_INFO","database")
username = config.get("DB_INFO","user")
pwd = config.get("DB_INFO","password")
print server_info,db,username,pwd
conn =
_mssql.connect(server=server_info,database=db,user =username,password=pwd)

but following does work

conn =
_mssql.connect(server='server',database='database' ,user='user',password='password')


Config file looks like following

[DB_INFO]
server = "server"
database = "database"
user = "user"
password = "password"


But I cannot figure out why? Any ideas or help will be highly
appreciated. Thanks!
 
Reply With Quote
 
 
 
 
Tim Golden
Guest
Posts: n/a
 
      04-26-2011
On 26/04/2011 14:48, Oltmans wrote:
> Greetings, I hope you're doing well. I'm stuck in a strange issue,
> most likely due to my own ignorance. I'm reading a config file using
> ConfigParser module and passing database related info to _mssql.


[ ... ]

> Config file looks like following
>
> [DB_INFO]
> server = "server"
> database = "database"
> user = "user"
> password = "password"



A config file isn't a Python file: you don't need (and
don't want) double-quotes around those values.

TJG
 
Reply With Quote
 
 
 
 
Thomas Rachel
Guest
Posts: n/a
 
      04-26-2011
Am 26.04.2011 15:48, schrieb Oltmans:

> Following doesn't work
>
>
> config = ConfigParser.ConfigParser()
> config.read('configs.txt')
> server_info = config.get("DB_INFO","server")
> db = config.get("DB_INFO","database")
> username = config.get("DB_INFO","user")
> pwd = config.get("DB_INFO","password")
> print server_info,db,username,pwd
> conn =
> _mssql.connect(server=server_info,database=db,user =username,password=pwd)
>
> but following does work
>
> conn =
> _mssql.connect(server='server',database='database' ,user='user',password='password')


Ok, if you are this far: what prevents you from trying

print server_info, db, username, pwd

and being aware that IF there are " around, they are not part of the
string representation, but they are really there.


> Config file looks like following
>
> [DB_INFO]
> server = "server"
> database = "database"
> user = "user"
> password = "password"


I think if you will have seen the output above, you will probably see
what is wrong here: too many "s.

HTH & HAND!

Thomas
 
Reply With Quote
 
Oltmans
Guest
Posts: n/a
 
      04-26-2011
On Apr 26, 7:39*pm, Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-
a470-7603bd3aa...@spamschutz.glglgl.de> wrote:
> Am 26.04.2011 15:48, schrieb Oltmans:
>
>
>
>
>
>
>
>
>
> > Following doesn't work

>
> > config = ConfigParser.ConfigParser()
> > config.read('configs.txt')
> > server_info = config.get("DB_INFO","server")
> > db = config.get("DB_INFO","database")
> > username = config.get("DB_INFO","user")
> > pwd = config.get("DB_INFO","password")
> > print server_info,db,username,pwd
> > conn =
> > _mssql.connect(server=server_info,database=db,user =username,password=pwd)

>
> > but following does work

>
> > conn =
> > _mssql.connect(server='server',database='database' ,user='user',password='pa ssword')

>
> Ok, if you are this far: what prevents you from trying
>
> print server_info, db, username, pwd
>
> and being aware that IF there are " around, they are not part of the
> string representation, but they are really there.
>
> > Config file looks like following

>
> > [DB_INFO]
> > server = "server"
> > database = "database"
> > user = "user"
> > password = "password"

>
> I think if you will have seen the output above, you will probably see
> what is wrong here: too many "s.


Many thanks, really appreciate help.
>
> HTH & HAND!
>
> Thomas


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot get past POST screen John Orrett Computer Support 11 01-01-2007 05:59 PM
How should multiple (related) projects be arranged (structured) and configured so that they can share code, have a related package structure and enable proper unittesting, and ensuring no namespace collisions ToddLMorgan@gmail.com Python 14 04-21-2006 04:03 PM
Cannot get past Object Reference Error danielle.m.manning@gmail.com ASP .Net 1 03-28-2006 11:43 PM
Cannot get past Object Reference Error danielle.m.manning@gmail.com ASP .Net 2 03-28-2006 11:17 PM
How should threads be terminated? (related to 'Help with thread related tracebacks') Maxwell Hammer Python 7 06-18-2005 04:20 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57