Re: Python Help Needed

Regarding the filename part, are you specifying the name as a program parameter? If so, spaces could be breaking it.

I'm not sure if the forum is removing part of the code, but that code should be throwing runtime errors.

    with open("{}".format(filename), "rb") as infile:
        infile.read()

The infile.read() here is redundant because <file object>.read() returns the entire content of the file as a string. This isn't allocated to anything so it will just read the file and do nothing. You don't really need to format a string here either since there isn't really any other text in the string, you can just call with open(filename, "r") as infile instead. Also binary and textfiles are different, I recommend just going with the default "r" file mode. This is actually default so you don't even need to specify the second parameter of "r".

for line in file:

your input file is named infile. The type of the file object is file, so that code is literally trying to iterate over the type object of a file.

If you do for line in infile, you may end up with some strange blank lines and characters, I don't really know why. Python actually has a readlines method on file objects so you can just call lines = infile.readlines() for example then iterate through those.

You can use <string>.replace(original, replacement) to replace characters. This also lets you replace them with the empty string. So you can just do line.replace("%", "") to remove all instances of a % character in a string.



_______________________________________________
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : stewie via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : tabutcu via Audiogames-reflector

Reply via email to