python and MySQL - 3 questions

Discussion in 'Python' started by el chupacabra, Oct 10, 2005.

  1. I'm using mysqldb module and python 2.4. I'm a newbie. Thanks in advance.

    1. Output desired:

    "hello"
    "world"

    I know that MySQL takes \n and \t and what not.

    But my python script, it takes that \n as literal. Meaning, when I retrieve the records, they show up like "hello \n world".

    How can keep formatting when inserting data to table?

    This is what I have:

    cursor.execute('insert into table values (%s, %s, %s, %s)', (newId, insertEntryName, insertLastName, insertSSN)


    2. How can make my python show *** (stars) when entering user passwords?

    3. Is it possible to make Python/MySQL transactions secure, encrypted? Can you point me to readings or something?



    --------------= Posted using GrabIt =----------------
    ------= Binary Usenet downloading made easy =---------
    -= Get GrabIt for free from http://www.shemes.com/ =-
     
    el chupacabra, Oct 10, 2005
    #1
    1. Advertising

  2. <<< cue theme from "The Prisoner" >>>
    "Information.... We want... Information..."

    On Mon, 10 Oct 2005 05:03:40 GMT, "el chupacabra" <>
    declaimed the following in comp.lang.python:

    > I'm using mysqldb module and python 2.4. I'm a newbie. Thanks in advance.
    >
    > 1. Output desired:
    >
    > "hello"
    > "world"
    >
    > I know that MySQL takes \n and \t and what not.


    Show us the exact input...

    print repr(instuff)

    Then show us the exact output...

    print repr(outstuff)

    >>> import MySQLdb
    >>> cn = MySQLdb.Connect(host="localhost", db="test", user="test")
    >>> cr = cn.cursor()
    >>> instuff = "Dennis\tLee\nBieber"
    >>> cr.execute("insert into junk (aString) values (%s)", instuff)

    1L
    >>> cn.commit()
    >>> cr.execute("select ID, aString from junk")

    1L
    >>> (id, outstuff) = cr.fetchone()
    >>> print repr(instuff)

    'Dennis\tLee\nBieber'
    >>> print repr(outstuff)

    'Dennis\tLee\nBieber'
    >>>
    >>> print instuff

    Dennis Lee
    Bieber
    >>> print outstuff

    Dennis Lee
    Bieber
    >>>


    Sure look the same to me...


    >
    > 2. How can make my python show *** (stars) when entering user passwords?
    >


    Command line console, Tkinter, Win32 native, wxPython, GTK? They all
    have different ways...

    However, as a start... open the Python help system and look for
    password... You should find:

    """
    6.13 getpass -- Portable password input

    The getpass module provides two functions:

    getpass( [prompt])
    Prompt the user for a password without echoing. The user is prompted
    using the string prompt, which defaults to 'Password: '. Availability:
    Macintosh, Unix, Windows.

    getuser( )
    Return the ``login name'' of the user. Availability: Unix, Windows.
    This function checks the environment variables LOGNAME, USER, LNAME and
    USERNAME, in order, and returns the value of the first one which is set
    to a non-empty string. If none are set, the login name from the password
    database is returned on systems which support the pwd module, otherwise,
    an exception is raised.
    """

    > 3. Is it possible to make Python/MySQL transactions secure, encrypted? Can you point me to readings or something?
    >


    SSH?

    The MySQL reference manual?

    Page 141/142 of the Black/Brown MySQL/O'Reilly manual has a chapter
    on using SSH on Windows for a secure connection.

    I'd expect the newer MySQL press manuals have the same chapter.
    --
    > ============================================================== <
    > | Wulfraed Dennis Lee Bieber KD6MOG <
    > | Bestiaria Support Staff <
    > ============================================================== <
    > Home Page: <http://www.dm.net/~wulfraed/> <
    > Overflow Page: <http://wlfraed.home.netcom.com/> <
     
    Dennis Lee Bieber, Oct 10, 2005
    #2
    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. Ravi
    Replies:
    6
    Views:
    1,410
    Suchandra Thapa
    Jul 21, 2003
  2. Replies:
    2
    Views:
    6,196
  3. washakie
    Replies:
    4
    Views:
    925
    washakie
    Jan 15, 2008
  4. Jeffrey H. Coffield
    Replies:
    1
    Views:
    1,861
  5. dave
    Replies:
    4
    Views:
    1,371
    Steve Holden
    Nov 18, 2010
Loading...

Share This Page