#๐ what SHOULD be done if someone makes an object of this class
39 messages ยท Page 1 of 1 (latest)
@uncut peak
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
class Puzzle:
def __init__(self, path=None):
self.load_buffer(path)
if self.buffer:
self.read_buffer()
def load_buffer(self, path):
self.buffer = open(path, mode="rb") if path else None
def read_buffer(self):
self.bytes = self.buffer.read()
def answer(self):
return "".join(chr(self.bytes[x]) for x in [446, 918, 1692, 2004, 2681, 2888, 3200, 3289, 4131, 4413, 4492,
4801, 4935, 5119, 5532, 5748, 5976, 7408, 7623, 8245, 8374])
def __str__(self):
return self.answer()
that's nothing
what do you want to happen ?
this code just tells python "what SHOULD be done if someone makes an object of this class "
you are not actually making an object from this class , you are not printing anything , thats why nothing is happening
hm?
what mena
saul
but like count
446, 918, 1692, 2004, 2681, 2888, 3200, 3289, 4131, 4413, 4492, 4801, 4935,5119, 5532, 5748, 5976, 7408, 7623, 8245, 8374
sorry but im confusion so i want the count like?
what SHOULD be done if someone makes an object of this class
uh
@dusky shadow
It seems to me that if you went obj=Puzzle("some_filename_here") it should read the whole file, and if someone asked for obj.answer() they should get a string containing the concatenation of selected bytes from the file. But I haven't tried it.
I mean: just run the code. Python will do what the code says to do.
its works?
My computer always does exactly what I tell it to do but sometimes I have
trouble finding out what it was that I told it to do.
- Dick Wexelblat <[email protected]>
what?
Sorry, that last bit is a humorous quote, not actually help.
Our problem is: you've provided some code. We can see what it would do. What it "should" do depends on what "should" comes from? From the code? From the mind of the person who wrote the code? From the mind of the person who asked (you?) to write the code?
Possibly we do not understand your question properly.
def answer(self):
return "".join(chr(self.bytes[x]) for x in [ 446, 918, 1692, 2004, 2681, 2888, 3200, 3289, 4131, 4413, 4492,
4801, 4935, 5119, 5532, 5748, 5976, 7408, 7623, 8245, 8374])
but the answer nothing
Two things:
- you define a class
Puzzle. That's fine, but it runs no code. - if someone makes an bject of this class eg
obj = Puzzle("some_filename_here")then that runs the code called from the__init__method. But none of that code prints anything. It just loads the file into memory.
You need to call print(). For example:
obj = Puzzle("some_filename_here")
print(obj.answer())
print(obj)
uh
that's not work?
File "c:\Users\User\OneDrive\Documents\puzz\sss.py", line 21, in <module>
obj = Puzzle("some_filename_here")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\User\OneDrive\Documents\puzz\sss.py", line 3, in __init__
self.load_buffer(path)
File "c:\Users\User\OneDrive\Documents\puzz\sss.py", line 9, in load_buffer
self.buffer = open(path, mode="rb") if path else None
^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'some_filename_here'
what some file here?
U need to change that with the directory of ur file
oh?
The path
Hurray :), if u dont have any more questions use !close
!close
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.