473,473 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Hiding

Jay
Well, im not no expert on the python programming language but i just
wanted to know if there was a quick way to hide certain things when
programming in python. Such as, i wanted some music or sound effects
with my python program. So, i type...

print "Music is by blah blah"
music-file = open(file containing the music"
hide(music-file)

thats wat im looking for, something i can hide the opening of files
because if i open that file, Windows Media Player will open and i would
like to hide that. And advise????

Jul 29 '05 #1
9 2152
Well, using the open function in Python doesn't launch any application
associated with the file (such as Media Player). It just makes the
contents of the file accessible to your Python code. Also, I think
using file("C:\file.txt") is now preferred to open("C:\file.txt").

To answer the specific question of how to play a music file in Python,
search Google Groups for: pygame.mixer.music.load("music.mp3")
That will bring up a useful thread. Note that you will need to install
a module such as pygame or pymedia; they are not in the standard
library.

In general, I would also recommend some of the many good Python
tutorials. Some are listed here:
http://wiki.python.org/moin/BeginnersGuide

Good luck!

Jul 29 '05 #2
I can say with some certainty that opening a "music file" with open
won't launch media player. If rather, you do os.system('musicfile.mp3')
it will launch whatever application is associated with the file type
..mp3. You can either automate Windows Media player or use pymedia
to play such files.

Here are some links that might be of interest:

http://www.win32com.de/index.php?opt...141&Itemid=259

http://pymedia.org/tut/

Larry Bates
Jay wrote:
Well, im not no expert on the python programming language but i just
wanted to know if there was a quick way to hide certain things when
programming in python. Such as, i wanted some music or sound effects
with my python program. So, i type...

print "Music is by blah blah"
music-file = open(file containing the music"
hide(music-file)

thats wat im looking for, something i can hide the opening of files
because if i open that file, Windows Media Player will open and i would
like to hide that. And advise????

Jul 29 '05 #3
Jason Drew wrote:
Also, I think using file("C:\file.txt") is now preferred
to open("C:\file.txt").


Guido has said he wants to keep open() around as the way to open a
file-like object, with the theory that in the future open might also
support opening non-files (e.g. urls). So open("C:\file.txt") is still
fine, though isinstance(f, open) is probably not. ;)

STeVe
Jul 29 '05 #4
Steven Bethard wrote:
So open("C:\file.txt") is still fine


I think it is more like it is recommended, not just OK.
--
Benji York
Jul 29 '05 #5
Jason Drew wrote:
Also, I think
using file("C:\file.txt") is now preferred to open("C:\file.txt").


As others have noted, "open" is preferred as the method for opening
files, while "file" is the _type_ involved, for testing or subclassing
or what-have-you.

But neither file("C:\file.txt") nor open("C:\file.txt") is actually
correct at all, unless you have strange files whose names start with
ASCII FF characters. '\f' is an escape sequence, equivalent to '\x0c'.

Always use forward slashes ("C:/file.txt") in path names unless you are
passing them to the shell, or use raw strings (r"C:\file.txt") to avoid
mysterious problems with escape sequences.

-Peter
Jul 29 '05 #6
Jay
thanks for the great info and urls, i have downloaded the pymedia
module and playing around with it now. Thx alot

Jul 30 '05 #7
Jay
but also, wat if i needed to hide the loading of a file or the even
hide the whole python window to run in background?? is there no module
or function i can use????

Jul 30 '05 #8
* Jay (2005-07-30 08:51 +0100)
but also, wat if i needed to hide the loading of a file
As others have pointed out: your question is pointless as opening a
file doesn't load it or open it in your preferred application.

You are confusing Operating System semantics with Python semantics.

You're probably only asking this question because you've never
actually tried it.

The solution for your problem is to read a beginner's tutorial about
Python.
or the even hide the whole python window to run in background?? is
there no module or function i can use????


On windows: use pythonw.exe instead of python.exe.
Jul 30 '05 #9
Ah, good point, thanks. Must stop forgetting that "C:\file.txt" is bad.

The whole open()/file() clairification is useful too. The Python docs
for the file() constructor simply state that, "File objects ... can be
created with the built-in constructor file() described in section 2.1,
'Built-in Functions.'"
(http://python.org/doc/2.4.1/lib/bltin-file-objects.html)

That's followed by a footnote that states, "file() is new in Python
2.2. The older built-in open() is an alias for file()."

At first sight, that to me suggests that open() has been somewhat
deprecated by file().

However, the description of many of the file methods on the same page
refers to opening files using open(), e.g.:
"mode: The I/O mode for the file. If the file was created using the
open() built-in function, this will be the value of the mode
parameter."

It all becomes relatively clear in section 2.1, "Built-in Functions"
where the entry for file() states, "The file() constructor is new in
Python 2.2 and is an alias for open(). Both spellings are equivalent.
The intent is for open() to continue to be preferred for use as a
factory function which returns a new file object. The spelling, file is
more suited to type testing (for example, writing 'isinstance(f,
file)')."

I guess that clears it up. Though perhaps the Python doc for the file()
constructor should add that open() is the preferred general-purpose way
to open a file or file-like object?

Thanks again

Aug 1 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Lorenzo Villari | last post by:
I premise I don't know C++ well but... I wondered what is this data hiding thing... I mean, if I can look at the header (and i need it beacuse of the class), then what's hidden? Can someone give...
2
by: coolwarrior | last post by:
Hi, 1_I want to know the difference between "data hiding" , "steganography" ,"watermarking" ,"capsulation" related to DSP. 2_There r plenty of informaion about data hiding for images on the web...
6
by: harrylmh | last post by:
Hi, I'm learning C# and I just don't quite understand the need for polymorphism. why do we need to use it? how does a base class variable holding a derived class instance do any good? Also,...
17
by: Bob Weiner | last post by:
What is the purpose of hiding intead of overriding a method? I have googled the question but haven't found anything that makes any sense of it. In the code below, the only difference is that...
9
by: bob | last post by:
Hi, I know there exists a good reason why the designers of c++ decided that function hiding should exist. But I don't know why. Can anybody provide a good reason/example of a case where function...
3
by: Nicolas Castagne | last post by:
Hi all, I have been wondering for a while why function hiding (in a derived class) exists in C++, e.g. why when writing class Base { void foo( int ) {} }; class Derived: public Base { void...
2
by: subramanian100in | last post by:
Is my following understanding correct ? Data abstraction means providing the interface - that is, the set of functions that can be called by the user of a class. Information hiding means...
17
by: rohitchawla | last post by:
i am trying to show and hide a div when onmouseover and onmouseover another div element. i am setting a setTimeout duration on onmouseout to delay the hiding of div for around two second The...
162
by: Sh4wn | last post by:
Hi, first, python is one of my fav languages, and i'll definitely keep developing with it. But, there's 1 one thing what I -really- miss: data hiding. I know member vars are private when you...
27
by: matt | last post by:
Hello group, I'm trying to become familiar with the information hiding design rules, and I have a lot (3) of questions for all you experts. AFAIK, a generic module has 2 files: ...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.