473,394 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Syntax error on filename

>>> python WavHeader.py hello.wav
File "<stdin>", line 1
python WavHeader.py hello.wav
^(this arrow mark is actually below 'r' of WavHeader.py)
SyntaxError : invalid syntax
Attached Files
File Type: txt WavHeader.txt (3.3 KB, 749 views)
Apr 2 '10 #1
16 6812
bvdet
2,851 Expert Mod 2GB
I tested your script from the Command Prompt without a hitch. At the python prompt, use the import statement. This worked for me:
Expand|Select|Wrap|Line Numbers
  1. >>> import WaveHeader
  2. >>> WaveHeader.PrintWavHeader("sample.wav")
  3. Subchunks Found:
  4. fmt ,  data,
  5.  
  6. Data Chunk located at offset [36] of data length [15022108] bytes
  7. BitsPerSample:  16
  8. NumChannels:  2
  9. ChunkSize:  15022144
  10. Format:  WAVE
  11. Filename:  sample.wav
  12. ByteRate:  176400
  13. Subchunk1Size:  16
  14. AudioFormat:  1
  15. BlockAlign:  4
  16. SampleRate:  44100
  17. >>> 
Apr 2 '10 #2
i'm still facing the same problem. i'm new to this python thing. is thr something wrong with some other configuration? as in computer's? or what?
and in the IDLE when i'm doing with the import..
this is what i get:
>>> import WavHeader
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import WavHeader
ImportError: No module named WavHeader

>>> WavHeader.PrintWavHeader("hello.wav")
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
WavHeader.PrintWavHeader("hello.wav")
NameError: name 'WavHeader' is not defined


reply from your end is eagerly awaited.
Apr 2 '10 #3
bvdet
2,851 Expert Mod 2GB
In IDLE, import the os module and set the current working directory to the directory containing WaveHeader.py. If the WAV file is in another directory, use the full path in the argument.

Expand|Select|Wrap|Line Numbers
  1. import os
  2. os.chdir("XX:/directory_name")
Apr 2 '10 #4
bvdet
2,851 Expert Mod 2GB
An alternative: import sys and append the path to the directory to sys.path.
Expand|Select|Wrap|Line Numbers
  1. import sys
  2. sys.path.append("XX:/directory_name")
You may have to create a file named "__init__.py" and place it in the same directory as WaveHeader.py. It need not have anything in it.
Apr 2 '10 #5
I am facing some wierd problems here.I deleted the first few lines of the code from the IDLE including the ">>>" sign till so that the first line read
"# WavHeader.py
#Extract .....
"
Now I start the python command line and at the >>> promt I give the following command:

>>> import os
>>> os.system("python WavHeader.py hello.wav")
Now the earlier error,i.e. the syntax error disappears but a new error appears as:

File "WavHeader.py", line 17
print "%s:" % (key), structHeaderFields[key]

Now I really dont know why I am having all these errors and amreally feeling low because I was expecting the code to run without a hitch as you did.But still I am stuck.
Please help me out with this one.
Awaiting your response.
Apr 3 '10 #6
bvdet
2,851 Expert Mod 2GB
Open the file in Idle. This sets the current working directory to the location of the module. At the Python prompt of the shell window:
Expand|Select|Wrap|Line Numbers
  1. >>> import WaveHeader
  2. >>> WaveHeader.PrintWavHeader("sample.wav")
  3. Subchunks Found: 
  4. fmt ,  data,  
  5.  
  6. Data Chunk located at offset [36] of data length [15022108] bytes
  7. BitsPerSample:  16
  8. NumChannels:  2
  9. ChunkSize:  15022144
  10. Format:  WAVE
  11. Filename:  sample.wav
  12. ByteRate:  176400
  13. Subchunk1Size:  16
  14. AudioFormat:  1
  15. BlockAlign:  4
  16. SampleRate:  44100
  17. >>> 
Keep trying, you are bound to hit it eventually. :)
Apr 4 '10 #7
i do as above and i get the following:

>>> import WavHeader
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import WavHeader
File "E:\Python31\WavHeader.py", line 17
print "%s: " % (key), structHeaderFields[key]
^
SyntaxError: invalid syntax
Apr 4 '10 #8
^ is below the second "
Apr 4 '10 #9
bvdet
2,851 Expert Mod 2GB
What version of Python are you using? If it's 3.0 or 3.1, print is a function whereas it was a statement in 2.X.
Apr 4 '10 #10
it's Python 3.1

help me out, bro.
Apr 4 '10 #11
bvdet
2,851 Expert Mod 2GB
@joydeepdg
You can find the proper usage for the built-in function print() here.
Apr 4 '10 #12
which version of python are u using?
Apr 7 '10 #13
bvdet
2,851 Expert Mod 2GB
I am using 2.3 because that is the version embedded in the software I use for my work. I have 2.6 installed when I want to try something new.
Apr 7 '10 #14
Domi
2
I'm running into this exact same error and I can't for the life of me figure out what is going wrong. I'm doing the Python tutorials made by google

Using the following code

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/python -tt
  2. # Copyright 2010 Google Inc.
  3. # Licensed under the Apache License, Version 2.0
  4. # http://www.apache.org/licenses/LICENSE-2.0
  5.  
  6. # Google's Python Class
  7. # http://code.google.com/edu/languages/google-python-class/
  8.  
  9. """A tiny Python program to check that Python is working.
  10. Try running this program from the command line like this:
  11.   python hello.py
  12.   python hello.py Alice
  13. That should print:
  14.   Hello World -or- Hello Alice
  15. Try changing the 'Hello' to 'Howdy' and run again.
  16. Once you have that working, you're ready for class -- you can edit
  17. and run Python code; now you just need to learn Python!
  18. """
  19.  
  20. import sys
  21.  
  22. # Define a main() function that prints a little greeting.
  23. def main():
  24.   # Get the name from the command line, using 'World' as a fallback.
  25.   if len(sys.argv) >= 2:
  26.     name = sys.argv[1]
  27.   else:
  28.     name = 'World'
  29.   print 'Hello', name
  30.  
  31. # This is the standard boilerplate that calls the main() function.
  32. if __name__ == '__main__':
  33.   main()

The most irritating thing is, using the shell, I can open the module and run it (f5) and it prints Hello World, but every time I navigate over to the directory and try running it through the command line interface (import hello, python hello.py) it keeps giving me this error. Sorry to the OP about pseudo hijacking your thread here :P but maybe this might shed more light on the issue. I'm using python 2.6
Apr 7 '10 #15
Domi
2
On further inspection, it doesn't seem to be noticing the command "python". I get the exact same error when I do something random like:

>>>asdfranom hello.py

when I do >>>python it says that it is not defined. :S Is this supposed to happen?
Apr 7 '10 #16
bvdet
2,851 Expert Mod 2GB
When you are at the python command prompt, import the module then execute the function as in:
Expand|Select|Wrap|Line Numbers
  1. >>> import math
  2. >>> math.sqrt(9376)
  3. 96.829747495281637
  4. >>> 
Modules define a variable, __name__, that contains the module name. When you run the opened file in Idle (F5), it becomes the top-level module of the interpreter, and __name__ is assigned to "__main__". The code:
Expand|Select|Wrap|Line Numbers
  1. if __name__ == '__main__':
  2.     main()
therefore executes the function main().

Try this - assuming your module is named "modulename.py":
Expand|Select|Wrap|Line Numbers
  1. import modulename
  2. modulename.main()
Apr 7 '10 #17

Sign in to post your reply or Sign up for a free account.

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
17
by: Paul | last post by:
HI! I am trying to dynamically add content into Div tags with the use of JavaScript. it loads the page but adds a few characters. the script is below. <script language="JavaScript">...
1
by: Trevor | last post by:
Also posted in general ASP.NET forum. System.IO.IOException: The filename, directory name, or volume label syntax is incorrect. I have hit a problem for which I can find no solutions. Has...
6
by: DBDriver | last post by:
I have an Access 97 database on WinXP with a linked Excel table of about 100,000 rows. I'm trying to construct a query that will give me an editable datasheet showing records where data in a pair...
2
by: ssshhh | last post by:
hi! I'm usng SQL server and i want to rename a file using the xp_cmdshell. here's my code: declare @path varchar (20) declare @filename varchar (20) declare @new varchar (20) declare @cmd...
4
by: achroiet002 | last post by:
Hi, Please, can someone help me? My problem: I have put a command button onto a form, which retrieves two field values from the current record. With these two values, I am able to open a...
3
by: nvr | last post by:
Hi all I am doing the socket programming for the client side. but the code is not compiling and i am getting the below error ./Clientsend.c: line 11: syntax error near unexpected token `('...
2
by: HalfCoded | last post by:
Hi everyone, I am currently working at learning perl but come up with two problems i can't clear on my own. I use perl version 5.8 on windows xp The complete I am working on is supposed to...
9
akohistani
by: akohistani | last post by:
I am having Parse error problem with my newly purchased Php upload script I have uploaded the script and I get the error below Parse error: syntax error, unexpected $end in URL/functions.php on...
7
by: sumanta123 | last post by:
Dear Sir when i am getting the value from properties file the the path showing http://127.0.0.1:81/help/Subject of Issue.txt which is right. But in jsp in try block when pass SubjectofIssue path...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.