python and MySQL - 3 questions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • el chupacabra

    #1

    python and MySQL - 3 questions

    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/ =-

  • Dennis Lee Bieber

    #2
    Re: python and MySQL - 3 questions


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

    On Mon, 10 Oct 2005 05:03:40 GMT, "el chupacabra" <nowayjose@nowa y.com>
    declaimed the following in comp.lang.pytho n:
    [color=blue]
    > 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.[/color]

    Show us the exact input...

    print repr(instuff)

    Then show us the exact output...

    print repr(outstuff)
    [color=blue][color=green][color=darkred]
    >>> import MySQLdb
    >>> cn = MySQLdb.Connect (host="localhos t", db="test", user="test")
    >>> cr = cn.cursor()
    >>> instuff = "Dennis\tLee\nB ieber"
    >>> cr.execute("ins ert into junk (aString) values (%s)", instuff)[/color][/color][/color]
    1L[color=blue][color=green][color=darkred]
    >>> cn.commit()
    >>> cr.execute("sel ect ID, aString from junk")[/color][/color][/color]
    1L[color=blue][color=green][color=darkred]
    >>> (id, outstuff) = cr.fetchone()
    >>> print repr(instuff)[/color][/color][/color]
    'Dennis\tLee\nB ieber'[color=blue][color=green][color=darkred]
    >>> print repr(outstuff)[/color][/color][/color]
    'Dennis\tLee\nB ieber'[color=blue][color=green][color=darkred]
    >>>
    >>> print instuff[/color][/color][/color]
    Dennis Lee
    Bieber[color=blue][color=green][color=darkred]
    >>> print outstuff[/color][/color][/color]
    Dennis Lee
    Bieber[color=blue][color=green][color=darkred]
    >>>[/color][/color][/color]

    Sure look the same to me...

    [color=blue]
    >
    > 2. How can make my python show *** (stars) when entering user passwords?
    >[/color]

    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.
    """
    [color=blue]
    > 3. Is it possible to make Python/MySQL transactions secure, encrypted? Can you point me to readings or something?
    >[/color]

    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.
    --[color=blue]
    > =============== =============== =============== =============== == <
    > wlfraed@ix.netc om.com | Wulfraed Dennis Lee Bieber KD6MOG <
    > wulfraed@dm.net | Bestiaria Support Staff <
    > =============== =============== =============== =============== == <
    > Home Page: <http://www.dm.net/~wulfraed/> <
    > Overflow Page: <http://wlfraed.home.ne tcom.com/> <[/color]

    Comment

    Working...