Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

:: in strings in Python

Tags:

python

I've been learning Python and I must say I loved it. But as a new learners I am having some other problems as well:

Could you guys tell me whether it is a feature of Python or the library of itself.

I am checking how to connect to sqllite database and I came up with this article and there is a code sample over there as such below:

>>> from pysqlite2 import dbapi2 as sqlite
>>> connection = sqlite.connect('test.db')
>>> memoryConnection = sqlite.connect(':memory:')
>>> cursor = connection.cursor()

When he wrote memory as string, he put two : (colon) as well and I am wondering whether it is peculiar to library instead of Python itself.

like image 206
Tarik Avatar asked Apr 22 '26 03:04

Tarik


1 Answers

The ':memory:' string is entirely database dependent. As explained in the documentation for sqlite:

You can use ":memory:" to open a database connection to a database that resides in RAM instead of on disk.

As far as the Python language is concerned, ':memory:' is just a string like any other.

like image 69
NPE Avatar answered Apr 24 '26 18:04

NPE