小编vic*_*vic的帖子

__str__输出"0x00E4F558处的实例"

这是我第一次在这个网站上寻求帮助.我在这里寻找答案,但没有什么能真正为我清除.

我正在努力学习Python.我在"课堂"一章.以下代码:

class Character:
    def __init__(self, name, initial_health):
        self.name = name
        self.health = initial_health
        self.inventory = []

    def __str__(self):
        s  = "Name: " + self.name
        s += "| Health: " + str(self.health)
        s += "| Inventory: " + str(self.inventory)
        return s

    def grab(self, item):
        self.inventory.append(item)

me = Character("vic", 37)
me.grab("pencil")
me.grab("paper")
print str(me)
Run Code Online (Sandbox Code Playgroud)

...生产:

Name: vic| Health: 37| Inventory: ['pencil', 'paper']
Run Code Online (Sandbox Code Playgroud)

但是下面的代码,在我看来非常相似,打印出内存位置而不是变量本身:

import random
SUITS = ['C', 'S', 'H', 'D']
RANKS = ['A', '2', '3', '4', '5', '6', '7', '8', …
Run Code Online (Sandbox Code Playgroud)

python string

4
推荐指数
1
解决办法
201
查看次数

SQLite .output 标准输出

我正在尝试将 csv 文件导出为固定长度的文件。我正在使用 SQLite,因为我必须处理文件。

我遇到的问题是输出。

这是我从 sql 文件运行的代码:

.output stdout          --send output to screen
.echo off
.headers off 
.separator ','
.mode column

.open tmp.db
DROP TABLE IF EXISTS myData;

.import 'C:\2015.csv' myData
.width 4 4 1 6 16 2 6 

.output myData.txt      --send output to file
select * from myData;

.output stdout          --send output back to screen
.print "File was created."

DROP TABLE IF EXISTS myData;
vacuum;
.print "tmp.db vacuum complete"
.print "Type '.exit' or '.quit' to exit SQLite"

.exit …
Run Code Online (Sandbox Code Playgroud)

sqlite

1
推荐指数
1
解决办法
4876
查看次数

标签 统计

python ×1

sqlite ×1

string ×1