小编Lla*_*ama的帖子

Python 打印对象地址而不是值

我想打印已添加到列表中的所有曲目tracks[]。当我尝试这样做时,我得到的是该对象在内存中的地址,而不是它的实际值。我显然不明白对象创建/将对象从一个类传递到另一个类是如何工作的。

class Song:

    def __init__(self, title, artist, album, track_number):
        self.title = title
        self.artist = artist
        self.album = album
        self.track_number = track_number

        artist.add_song(self)


class Album:

    def __init__(self, title, artist, year):
        self.title = title
        self.artist = artist
        self.year = year

        self.tracks = []

        artist.add_album(self)

    def add_track(self, title, artist=None):
        if artist is None:
            artist = self.artist

        track_number = len(self.tracks)

        song = Song(title, artist, self, track_number)

        self.tracks.append(song)
        print(self.tracks)


class Artist:
    def __init__(self, name):
        self.name = name

        self.albums = []
        self.songs = [] …
Run Code Online (Sandbox Code Playgroud)

python oop inheritance init

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

AWS Lambda 和 S3 - 上传的 pdf 文件是空白的

我有一个非常简单的函数,可以使用 AWS Lambda 和 Amazon API Gateway将 PDF 文件上传到 AWS S3 ( https://codedestine.com/aws-s3-putobject-java/ )。

我尝试上传一个包含 2 页文本的 PDF 文件。上传后,PDF 文件(在 AWS S3 上)有 2 个空白页。

这是我用来在 AWS S3 上上传 PDF 文件的方法。

public static void uploadFile2(MultipartFile mpFile, String fileName) throws IOException{
   
    String dirPath = System.getProperty("java.io.tmpdir", "/tmp");
    File file = new File(dirPath  + "/" + fileName);

    OutputStream ops = new FileOutputStream(file);
    ops.write(mpFile.getBytes());

    s3client.putObject("fakebucketname", fileName, file);

}
Run Code Online (Sandbox Code Playgroud)

为什么上传的PDF文件是空白的?

java spring amazon-s3 amazon-web-services aws-lambda

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