Cannot get past this string related issue

Discussion in 'Python' started by Oltmans, Apr 26, 2011.

  1. Oltmans

    Oltmans Guest

    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!
     
    Oltmans, Apr 26, 2011
    #1
    1. Advertising

  2. Oltmans

    Tim Golden Guest

    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
     
    Tim Golden, Apr 26, 2011
    #2
    1. Advertising

  3. 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
     
    Thomas Rachel, Apr 26, 2011
    #3
  4. Oltmans

    Oltmans Guest

    On Apr 26, 7:39 pm, Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-
    > 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
     
    Oltmans, Apr 26, 2011
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lloyd Sheen
    Replies:
    13
    Views:
    461
    Hermit Dave
    Jan 25, 2004
  2. knutivar
    Replies:
    2
    Views:
    336
    bruce barker
    Dec 9, 2004
  3. Replies:
    2
    Views:
    1,684
    Steve C. Orr [MVP, MCSD]
    Mar 29, 2006
  4. Replies:
    1
    Views:
    394
    Erik Funkenbusch
    Mar 29, 2006
  5. Replies:
    5
    Views:
    667
Loading...

Share This Page